Skip to content

use session_class in database tasks - #237

Open
chaadow wants to merge 1 commit into
rails:mainfrom
chaadow:patch-1
Open

use session_class in database tasks#237
chaadow wants to merge 1 commit into
rails:mainfrom
chaadow:patch-1

Conversation

@chaadow

@chaadow chaadow commented Jul 18, 2026

Copy link
Copy Markdown

@rafaelfranca BTW I believe this can be simplfied to only where( created_at < ?, cutoff_period)

the example in the rails guides, uses a different period for each column where(updated_at: ...time.ago).or(where(created_at: ...2.days.ago)).delete_all) ( check : https://guides.rubyonrails.org/security.html#session-expiry )

I'm in favor of only keeping created_at and adding an index on that column instead of an index on updated_at because adding an index on updated_at ( a column which is constantly/naturally updated almost every single time) prevents Heap Only Tuple (HOT ) updates on PostgreSQL, which can lead to write amplification / more WAL etc...

@chaadow

chaadow commented Jul 18, 2026

Copy link
Copy Markdown
Author

@rafaelfranca also would you mind me using in_batches(use_ranges: true) to further optimize the SQL queries and make them index-only scans, otherwise the sorting is using the primary key ( id) by default

@rafaelfranca

Copy link
Copy Markdown
Member

No. Let's use in batches as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants