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

  • Home
  • SEARCH
  • 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 8375409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:10:10+00:00 2026-06-09T15:10:10+00:00

I recently added User activity tracking functionality to my application which tracks user interaction

  • 0

I recently added User activity tracking functionality to my application which tracks user interaction with several models, and several different actions within each model.

class User

  has_many :activities, :order => 'created_at desc'     

  def log_activity(object, type)
    activities.create(:subject_type => object.class.name, :subject_id => object.id, :subject_action_type => type)
  end 

end

Now I call this method after a User creates/updates/deletes various objects and display this activity on the user profile. I imagine that after a while the Activities table will contain so many records it’s going to get to the point where it effects load times. I was wondering what a good implementation would be to manage this in a user-friendly way and keep my database running smoothly.

I was thinking of setting up some kind of scheduled task that cleans up old records after x amount of time. Perhaps you can give some advice as to how to accomplish this or recommend an even better solution?

I’m using PostgreSQL as my database of choice.

  • 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-06-09T15:10:12+00:00Added an answer on June 9, 2026 at 3:10 pm

    Your activities lazy loads so it won’t pull in all of the associated activities unless you ask for them. So when you say this:

    activities.create(...)
    

    All you’re doing to the database is a single INSERT: there is no select * from activities where ... to build activities, there’s just the INSERT from the create call.

    So you don’t have anything to worry about from your log_activity method.

    If you want to limit the size of your activities table then a simple:

    Activity.connection.execute("delete from activities where created_at < now() - interval '10 days'")
    

    every now and then should be fine to clear out the dead wood. The '10 days' is, of course, just for illustration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have A game to which I recently added a global high score functionality
I recently added a feature to a large application written in Delphi (version 2009)
I recently added some url re-writing to my web application and had to added
I have recently added a new column (age) to a database table (user). I
I recently added devise confirmable module to my rails app. My application runs well
I recently moved a django app from c:\Users\user\django-projects\foo\foobar to c:\Python25\Lib\site-packages\foo\foobar (which is on the
As part of getting our application ready for Windows7, we recently added a manifest
I have a brand spanking new cPanel server. cPanel recently added xcache functionality right
I'm developing an newsletter sending application on C#/.NET platform. I've recently added the module
I have an international company that has recently been added, which is named BLA

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.