0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-13 23:41:24 -05:00

Fix minor issues on session expiration handling

This commit is contained in:
Andrey Antukh 2022-02-15 13:25:06 +01:00
parent 82796822d1
commit e9fe1800e0

View file

@ -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)")