auth: move last_session update from gateway to auth

this should help in cases where the client has long-lived sessions (more
than a day)
This commit is contained in:
Luna Mendes 2018-10-27 23:48:28 -03:00
parent 80c29265f3
commit 4d4b075de9
2 changed files with 11 additions and 7 deletions

View File

@ -35,6 +35,17 @@ async def raw_token_check(token, db=None):
try:
signer.unsign(token)
log.debug('login for uid {} successful', user_id)
# update the user's last_session field
# so that we can keep an exact track of activity,
# even on long-lived single sessions (that can happen
# with people leaving their clients open forever)
await db.execute("""
UPDATE users
SET last_session = (now() at time zone 'utc')
WHERE id = $1
""", user_id)
return user_id
except BadSignature:
log.warning('token failed for uid {}', user_id)

View File

@ -406,13 +406,6 @@ class GatewayWebsocket:
# link the state to the user
self.ext.state_manager.insert(self.state)
# update last_session
await self.ext.db.execute("""
UPDATE users
SET last_session = (now() at time zone 'utc')
WHERE id = $1
""", user_id)
await self.update_status(presence)
await self.subscribe_all()
await self.dispatch_ready()