Skip to content

fix(session): Update last_seen when user session is validated - #50835

Merged
artonge merged 1 commit into
masterfrom
updateLastSeen
Jun 11, 2026
Merged

fix(session): Update last_seen when user session is validated#50835
artonge merged 1 commit into
masterfrom
updateLastSeen

Conversation

@solracsf

@solracsfsolracsf commented Feb 15, 2025

Copy link
Copy Markdown
Member

Summary

While doing some maintenance on my instance, I've saw a lot of users with last_seen timestamp a few months ago, like 7 months ago or even more than a year. So, I've disabled them.

A couple of minutes later, some of them were complaining their user account was disabled 😿

Example:

# occ user:info USER
- user_id: USER
- display_name: USER
- email: USER@email.com
- cloud_id: USER@my.instance.com
- enabled: true
- groups:
- Users
- quota: 10 GB
- storage:
- free: 10737418240
- used: 0
- total: 10737418240
- relative: 0
- quota: 10737418240
- last_seen: 2024-08-12T17:19:46+00:00
- user_directory: /var/www/data/USER
- backend: Database

As you can see, last_seen states user was last seen (wrongly) 6 months ago.
Yet, on the webserver log, we can see that this same user performed some operations only minutes ago:

cat /var/log/nginx/*.log | grep -F 'USER'
"[15/Feb/2025:11:08:49 +0100]" my.instance.com PROPFIND /remote.php/dav/calendars/USER/personal_shared_by_another/ 207 0.077 0.062 "DAVx5/4.3.12.1-ose (2023/12/27; dav4jvm; okhttp/4.12.0) Android/12"
"[15/Feb/2025:11:39:14 +0100]" my.instance.com PROPFIND /remote.php/dav/calendars/USER/personal/ 207 0.324 0.309 "DAVx5/4.3.12.1-ose (2023/12/27; dav4jvm; okhttp/4.12.0) Android/12"

Problem is that those users NEVER use the WebUI, they only use some apps to sync their data, like Calendar or Contacts sync, etc. So, they never complete a full logout + full login.

My proposal here is to update the last_seen timestamp also when we validate their session, since that, in my opinion, as an instance administrator, I want to be able to rely on the last_seen field to really know when the user was last seen (and by last seen, I mean user has done some kind of legit activity on the instance, while being a valid user). As per actual logic, it would be updated, at most, once every 60s.

IMO, this is actually a bug (not a feature) because updating last_seen field only on full logout + login is not reliable.

Please review.

Checklist

@solracsfsolracsf added 2. developing Work in progress technical debt 🧱 🤔🚀 labels Feb 15, 2025
@solracsfsolracsf self-assigned this Feb 15, 2025
@solracsfsolracsf changed the title fix(session): Update last seen when user session is validatedfix(session): Update last_seen when user session is validatedFeb 16, 2025
@susnux
susnux requested a review from come-ncFebruary 16, 2025 23:40
@solracsf

solracsf commented Feb 17, 2025

Copy link
Copy Markdown
MemberAuthor

I've put this change as-is into production 1 year ago (since v30). Now I can see that users listed seen before, by the system, as "months ago", are in fact active, and are now listed as last seen "minutes" or "hours" ago.

This is what I expect to be reported.

@come-nccome-nc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How often is that executed?
It turns last login into last activity, no?

I understand the issue though, for webdav each request is a login, no?

@solracsfsolracsf added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Feb 22, 2025
@solracsf

solracsf commented Feb 22, 2025

Copy link
Copy Markdown
MemberAuthor

How often is that executed?

As per actual logic, it would be updated, at most, once every 60s.

It turns last login into last activity, no?

Exactly, but I, as sysadmin, don't care if my user logged in 3 months ago; what's important to know is if the user is active (using/interactting the platform) or not. Column is (correctly) named last_seen and not last_login 😉

@solracsf
solracsf marked this pull request as ready for review February 22, 2025 08:05
@solracsfsolracsf added this to the Nextcloud 32 milestone Feb 22, 2025
@solracsf
solracsf requested review from a team, nfebe, provokateurin and sorbaugh and removed request for a teamMarch 11, 2025 17:49
This was referenced Aug 22, 2025
This was referenced Sep 2, 2025
@nextcloud-botnextcloud-bot mentioned this pull request Sep 10, 2025
@nextcloud-botnextcloud-bot mentioned this pull request Sep 18, 2025
This was referenced Sep 25, 2025
@nextcloud-botnextcloud-bot mentioned this pull request Jan 7, 2026
This was referenced Jan 14, 2026
@nextcloud-botnextcloud-bot mentioned this pull request Jan 22, 2026
This was referenced Jan 29, 2026
This was referenced Feb 11, 2026
@blizzzblizzz modified the milestones: Nextcloud 33, Nextcloud 34Feb 16, 2026
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf
solracsf requested a review from a team as a code ownerApril 6, 2026 16:24
@solracsf
solracsf requested review from artonge and removed request for a teamApril 6, 2026 16:24

@artongeartonge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we do that, I think we should update the last login only once every X minutes.

@nextcloud-botnextcloud-bot mentioned this pull request May 27, 2026
@nextcloud-botnextcloud-bot mentioned this pull request Jun 4, 2026
This was referenced Jun 5, 2026
@susnuxsusnux added the community pull requests from community label Jun 9, 2026
@susnuxsusnux removed this from the Nextcloud 34.0.1 milestone Jun 9, 2026
@salmart-dev

Copy link
Copy Markdown
Contributor

This looks good to me, the last login timestamp would be updated every minute. If this becomes a problem in terms of amount of writes, we could make the interval configurable as well, so admins can choose how often updates happen.

@artonge
artonge merged commit 86c2b91 into masterJun 11, 2026
179 checks passed
@artonge
artonge deleted the updateLastSeen branch June 11, 2026 09:38
@nextcloud-botnextcloud-bot mentioned this pull request Aug 11, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewscommunitypull requests from communitytechnical debt🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@solracsf@salmart-dev@artonge@come-nc@joshtrichards@susnux@blizzz@skjnldsv@nextcloud-bot