views:

35

answers:

1

I use authlogic for authentication and certain actions require a logged in user, which is controlled via a before_filter like the following. I also use friendly_id on the User model and internally everything there is a look up on the User model there are queries to the friendly_id slug table too. This results in at least 3 queries for certain page view and this happens quite often.

Is there a way to maintain this functionality without running these queries everytime?

I also use memcached as an object store. Is that a possiblity? does it work well with authlogic?

def require_user
        unless current_user
            store_location
            flash[:notice] = "You must be logged in to access this page"
            redirect_to new_user_sessions_url
            return false
        end
    end
A: 

I wouldn't worry about it too much. Rails is pretty smart and will cache the query's so basically it will only run it once. Keep an eye on your log files and see if you can find the queries in question, most likely they will have (cache) prepended suggestion that the query results were still in cache.

Maran
I see something like..[DEBUG 12-10-2010 13:52:37] User Load (0.5ms) SELECT * FROM `users` WHERE (`users`.`id` = '9') LIMIT 1. No cache prepended though, these are from my production logs.
badnaam
Well let's say it doesn't cache, as you can see it took 0.5ms to execute that query. It's not like you are getting a whole lot of speed improvement on that
Maran