Just speculating, but what if we rephrase the problem: the User after_save callbacks are expensive. Would it be possible to move whatever attributes the callbacks modify to another model?
your User.rb after_save callbacks to another model? On Jul 27, 8:06 pm, badnaam <asitkmis...@gmail.com> wrote: > I use authlogic for authentication and paperclip for handling user's > profile picture attachments. > > I use the following method to get the current_user > > def current_user_session > return @current_user_session if defined? > (@current_user_session) > @current_user_session = UserSession.find > end > > def current_user > return @current_user if defined?(@current_user) > @current_user = current_user_session && > current_user_session.record > end > > and the following after_save callback to regenerate the profile image > if the image has changed. > > after_save do |user| > if user.image_changed? > Delayed::Job.enqueue ImageJob.new(user.id) > end > end > > The current_user method issues a UserSession.find call and > Looking at the docs it seems UserSession.tries to Log the user > in, which results in an update to certain fields (updated_at, token > etc. but not the profile image), which results in a > save of the user record, which in my case results in after_save > callbacks firing. This after save callback checks to see if there has > been a change to user's profile image, which unnecessarily consumes > time. > > Now this is fine if the user indeed is trying to > update profile, but since I use current_user in many different places > within my app, this callback is getting fired (and its an expensive > call), for no reason. > > I understand this isn't exactly authlogic issue, but is there anyway I > can avoid this, i.e. either not update the user record or somehow > differentiate between what is a profile update and what is an update > resulting from this UserSession.find login? > > Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.