Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 948051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:10:53+00:00 2026-05-15T23:10:53+00:00

I use authlogic for authentication and paperclip for handling user’s profile picture attachments. I

  • 0

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

Here is the solution that worked based on bjg’s suggestion.

before_save :check_what_changed

def check_what_changed
if self.changed.sort == [“last_request_at”, “perishable_token”]
self.skip_profile_update = true
return true
else
self.skip_profile_update = false
return true
end
end

Update #2
I take that back that didn’t work, but it’s not really a problem with this solution, for some reason paperclip tries to save the attachments even before the after_save callback. This is likely a paperclip issue, no idea..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:10:53+00:00Added an answer on May 15, 2026 at 11:10 pm

    In a before_save callback, you could differentiate between a real profile change and the Authlogic related changes (last_request_at and updated_at attributes) using the Rails built-in dirty objects tracking facility. Something along these lines

    attr_accessor :skip_profile_update
    
    before_save do |model|
      model.skip_profile_update = (model.changed.sort == ['last_request_at', 'updated_at'])
    end
    
    after_save do |model|
      unless model.skip_profile_update
        # etc
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently use Authlogic in a web-app to handle user authentication, but have now
I use Authlogic for authentication in my Rails project. It provide default validation for
I'm using Authlogic for authentication in my app, using the standard User and UserSession
I am using Authlogic for my user authentication, and would like yo add roles
I couldn't find resources on how to use authlogic with sinatra . Or at
I'd like to know what would be the best practise to use: Authentication Authorization
I use the following to visualize the range of means when averaging n coin
Use: The user searches for a partial postcode such as 'RG20' which should then
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
Use case: A does something on his box and gots stuck. He asks B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.