mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 15:16:13 +02:00
✨ Fix minor issues on session expiration handling
This commit is contained in:
parent
82796822d1
commit
e9fe1800e0
1 changed files with 12 additions and 7 deletions
|
@ -30,8 +30,11 @@
|
||||||
(let [token (tokens :generate {:iss "authentication"
|
(let [token (tokens :generate {:iss "authentication"
|
||||||
:iat (dt/now)
|
:iat (dt/now)
|
||||||
:uid profile-id})
|
:uid profile-id})
|
||||||
|
now (dt/now)
|
||||||
params {:user-agent (get headers "user-agent")
|
params {:user-agent (get headers "user-agent")
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
|
:created-at now
|
||||||
|
:updated-at now
|
||||||
:id token}]
|
:id token}]
|
||||||
(db/insert! conn :http-session params)))
|
(db/insert! conn :http-session params)))
|
||||||
|
|
||||||
|
@ -82,8 +85,7 @@
|
||||||
|
|
||||||
(defmethod ig/prep-key ::session
|
(defmethod ig/prep-key ::session
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
(d/merge {:buffer-size 64}
|
(d/merge {:buffer-size 128} (d/without-nils cfg)))
|
||||||
(d/without-nils cfg)))
|
|
||||||
|
|
||||||
(defmethod ig/init-key ::session
|
(defmethod ig/init-key ::session
|
||||||
[_ {:keys [pool] :as cfg}]
|
[_ {:keys [pool] :as cfg}]
|
||||||
|
@ -154,7 +156,7 @@
|
||||||
|
|
||||||
(= :size reason)
|
(= :size reason)
|
||||||
(l/debug :task "updater"
|
(l/debug :task "updater"
|
||||||
:action "update sessions"
|
:hint "update sessions"
|
||||||
:reason (name reason)
|
:reason (name reason)
|
||||||
:count result))
|
:count result))
|
||||||
(recur))))))
|
(recur))))))
|
||||||
|
@ -183,17 +185,20 @@
|
||||||
|
|
||||||
(defmethod ig/init-key ::gc-task
|
(defmethod ig/init-key ::gc-task
|
||||||
[_ {:keys [pool max-age] :as cfg}]
|
[_ {:keys [pool max-age] :as cfg}]
|
||||||
|
(l/debug :hint "initializing session gc task" :max-age max-age)
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(let [interval (db/interval max-age)
|
(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)]
|
result (:next.jdbc/update-count result)]
|
||||||
(l/debug :task "gc"
|
(l/debug :task "gc"
|
||||||
:action "clean http sessions"
|
:hint "clean http sessions"
|
||||||
:count result)
|
:deleted result)
|
||||||
result))))
|
result))))
|
||||||
|
|
||||||
(def ^:private
|
(def ^:private
|
||||||
sql:delete-expired
|
sql:delete-expired
|
||||||
"delete from http_session
|
"delete from http_session
|
||||||
where updated_at < now() - ?::interval")
|
where updated_at < now() - ?::interval
|
||||||
|
or (updated_at is null and
|
||||||
|
created_at < now() - ?::interval)")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue