From e9fe1800e0a49c409b3d5a7d1236deafa614a166 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 15 Feb 2022 13:25:06 +0100 Subject: [PATCH] :sparkles: Fix minor issues on session expiration handling --- backend/src/app/http/session.clj | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/backend/src/app/http/session.clj b/backend/src/app/http/session.clj index 90e3d217d..b09ffaf1c 100644 --- a/backend/src/app/http/session.clj +++ b/backend/src/app/http/session.clj @@ -30,8 +30,11 @@ (let [token (tokens :generate {:iss "authentication" :iat (dt/now) :uid profile-id}) + now (dt/now) params {:user-agent (get headers "user-agent") :profile-id profile-id + :created-at now + :updated-at now :id token}] (db/insert! conn :http-session params))) @@ -82,8 +85,7 @@ (defmethod ig/prep-key ::session [_ cfg] - (d/merge {:buffer-size 64} - (d/without-nils cfg))) + (d/merge {:buffer-size 128} (d/without-nils cfg))) (defmethod ig/init-key ::session [_ {:keys [pool] :as cfg}] @@ -154,7 +156,7 @@ (= :size reason) (l/debug :task "updater" - :action "update sessions" + :hint "update sessions" :reason (name reason) :count result)) (recur)))))) @@ -183,17 +185,20 @@ (defmethod ig/init-key ::gc-task [_ {:keys [pool max-age] :as cfg}] + (l/debug :hint "initializing session gc task" :max-age max-age) (fn [_] (db/with-atomic [conn pool] (let [interval (db/interval max-age) - result (db/exec-one! conn [sql:delete-expired interval]) + result (db/exec-one! conn [sql:delete-expired interval interval]) result (:next.jdbc/update-count result)] (l/debug :task "gc" - :action "clean http sessions" - :count result) + :hint "clean http sessions" + :deleted result) result)))) (def ^:private sql:delete-expired "delete from http_session - where updated_at < now() - ?::interval") + where updated_at < now() - ?::interval + or (updated_at is null and + created_at < now() - ?::interval)")