Skip to content

Commit

Permalink
Add last active admin functionality
Browse files Browse the repository at this point in the history
The implementation is mostly based on DU4L#16
but we update the timer in the database instead of the frontend.
The update is done when the user fetches the profile,
so for every first load done in a new tab in the browser.

Please note that this commit can NOT be merged before TFNS#213
is merged since the migration files are now not consecutive.
The other PR contains a migration with ID 41, so this PR has a migration
with ID 42 (and this answers everything of course).
The migration will fail in this branch therefore. For testing, please
rename the file and use a throw away database.
  • Loading branch information
JJ-8 committed May 5, 2023
1 parent eff12be commit 78f239c
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 2,081 deletions.
33 changes: 33 additions & 0 deletions api/migrations/42-add-last-active.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ALTER TABLE ctfnote.profile
ADD COLUMN "lastactive" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP;


/* UpdateLastActive */
CREATE FUNCTION ctfnote.update_last_active ()
RETURNS void
AS $$
BEGIN
UPDATE ctfnote.profile
SET lastactive = now()
WHERE id = ctfnote_private.user_id ();
END;
$$
LANGUAGE plpgsql VOLATILE
SECURITY DEFINER;
GRANT EXECUTE ON FUNCTION ctfnote.update_last_active () TO user_guest;

CREATE OR REPLACE FUNCTION ctfnote.me ()
RETURNS ctfnote.profile
AS $$
SELECT ctfnote.update_last_active();
SELECT
*
FROM
ctfnote.profile
WHERE
id = ctfnote_private.user_id ()
LIMIT 1;

$$
LANGUAGE SQL
STRICT STABLE;
Loading

0 comments on commit 78f239c

Please sign in to comment.