From 80c29265f389c2dd3556bba27e196738739fa770 Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Sat, 27 Oct 2018 23:40:35 -0300 Subject: [PATCH] schema.sql: add users.last_session - gateway.websocket: update users.last_session SQL for instances: ```sql ALTER TABLE users ADD COLUMN last_session timestamp without time zone default (now() at time zone 'utc'); ``` --- litecord/gateway/websocket.py | 7 +++++++ schema.sql | 3 +++ 2 files changed, 10 insertions(+) diff --git a/litecord/gateway/websocket.py b/litecord/gateway/websocket.py index 515eac6..e32482e 100644 --- a/litecord/gateway/websocket.py +++ b/litecord/gateway/websocket.py @@ -406,6 +406,13 @@ 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() diff --git a/schema.sql b/schema.sql index e43ba45..b520d18 100644 --- a/schema.sql +++ b/schema.sql @@ -75,6 +75,9 @@ CREATE TABLE IF NOT EXISTS users ( phone varchar(60) DEFAULT '', password_hash text NOT NULL, + -- store the last time the user logged in via the gateway + last_session timestamp without time zone default (now() at time zone 'utc'), + PRIMARY KEY (id, username, discriminator) );