Skip to content

Conversation

@manuthecoder
Copy link
Contributor

Closes #10744

This pull request introduces a new background job to clear outdated user session data and schedules it to run daily. The job ensures sensitive session information is removed for sessions older than one year. Below are the most important changes:

Addition of a new job:

  • app/jobs/user/clear_old_user_sessions_job.rb: Added a new job ClearOldUserSessionsJob to the User namespace. This job iterates through user sessions older than one year and clears sensitive data such as device_info, os_info, timezone, ip, and location details (latitude and longitude).

Scheduling the job:

  • config/schedule.yml: Scheduled the new ClearOldUserSessionsJob to run daily at 3:00 AM with a low priority queue.

Internal discussion

@manuthecoder manuthecoder requested review from a team as code owners June 27, 2025 07:16
manuthecoder and others added 2 commits July 7, 2025 19:49
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@manuthecoder manuthecoder requested a review from davidcornu July 8, 2025 03:13
@manuthecoder
Copy link
Contributor Author

done! let me know if any further changes are needed, ty!

Comment on lines 84 to 90
def clear_metadata!
update_columns(
device_info: nil,
latitude: nil,
longitude: nil,
)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to use update to update! so that callbacks/validations run? Any thoughts @davidcornu?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to use update to update! so that callbacks/validations run?

Inclined to say yes unless we have a good reason not to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i'm on the same page.

typo in first message: to -> or*

@garyhtou garyhtou changed the title Clear older user sessions dailly [User Session] Clear metadata on older sessions Jul 16, 2025
@garyhtou garyhtou merged commit 8a73da2 into main Jul 16, 2025
7 of 8 checks passed
@garyhtou garyhtou deleted the clear-user-sessions-daily branch July 16, 2025 15:48
Sarvesh-Mk pushed a commit to Sarvesh-Mk/hcb that referenced this pull request Jul 21, 2025
### Closes hackclub#10744

This pull request introduces a new background job to clear outdated user
session data and schedules it to run daily. The job ensures sensitive
session information is removed for sessions older than one year. Below
are the most important changes:

### Addition of a new job:

*
[`app/jobs/user/clear_old_user_sessions_job.rb`](diffhunk://#diff-19bd9b2978ef88bf9ae1db00fbb346141d92e5d85c4cb816b8949d814f0c4792R1-R21):
Added a new job `ClearOldUserSessionsJob` to the `User` namespace. This
job iterates through user sessions older than one year and clears
sensitive data such as `device_info`, `os_info`, `timezone`, `ip`, and
location details (`latitude` and `longitude`).

### Scheduling the job:

*
[`config/schedule.yml`](diffhunk://#diff-18c4a92c666266e8bead5b6ddb034501022877cdf773c0d337499ed0a7f6d341R175-R179):
Scheduled the new `ClearOldUserSessionsJob` to run daily at 3:00 AM with
a low priority queue.

[Internal
discussion](https://hackclub.slack.com/archives/C047Y01MHJQ/p1750259883680629)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Gary Tou <[email protected]>
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.

[Login] Periodically clear out old UserSession entries

4 participants