🐛 Include tenant in library summary cache keys

The redis cache keys for the file library summary were built as
penpot.library-summary.<file-id>, missing the tenant component used
by the rest of the shared-infrastructure keys (rlimit, msgbus,
worker queues).

Build the key with a new file-summary-cache-key function that appends
the configured tenant, following the penpot.library-summary.<tenant>.<file-id>
pattern. Stale keys in the old format expire on their own with the
existing 30-day TTL.

Closes #11407

AI-assisted-by: glm-5.3-flash
This commit is contained in:
Andrey Antukh 2026-08-28 08:44:45 +00:00
parent 38004e6bb2
commit 948a97cc54
2 changed files with 7 additions and 4 deletions

View File

@ -515,8 +515,11 @@
(def ^:private file-summary-cache-key-ttl
(ct/duration {:days 30}))
(def file-summary-cache-key-prefix
"penpot.library-summary.")
(defn file-summary-cache-key
"Build the redis cache key for the file library summary. The tenant is
included to prevent key collisions between tenants sharing a redis instance"
[id]
(str "penpot.library-summary." (cf/get :tenant) "." id))
(defn- get-file-with-summary
"Get a file without data with a summary of its local library content"
@ -545,7 +548,7 @@
(rds/build-set-args {:ex file-summary-cache-key-ttl})))]
(if (contains? cf/flags :redis-cache)
(let [cache-key (str file-summary-cache-key-prefix id)]
(let [cache-key (file-summary-cache-key id)]
(or (rds/run! cfg get-from-cache cache-key)
(let [file (calculate-from-db)]
(rds/run! cfg persist-to-cache (:library-summary file) cache-key)

View File

@ -322,7 +322,7 @@
(defn- invalidate-caches!
[cfg {:keys [id] :as file}]
(rds/run! cfg (fn [{:keys [::rds/conn]}]
(let [key (str files/file-summary-cache-key-prefix id)]
(let [key (files/file-summary-cache-key id)]
(rds/del conn key)))))
(defn- attach-snapshot