# Paperclip, authlogic and callback issue

**URL:** <https://www.ruby-forum.com/t/paperclip-authlogic-and-callback-issue/192307>\
**Category:** Rails\
**Created:** [July 28, 2010, 2:09am UTC](https://www.ruby-forum.com/t/paperclip-authlogic-and-callback-issue/192307 "2010-07-28T02:09:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [July 28, 2010, 2:09am UTC](https://www.ruby-forum.com/t/paperclip-authlogic-and-callback-issue/192307/1 "2010-07-28T02:09:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [July 29, 2010, 6:31pm UTC](https://www.ruby-forum.com/t/paperclip-authlogic-and-callback-issue/192307/2 "2010-07-29T18:31:26Z")

</div>

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?
