mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 09:26:12 +02:00
🐛 Fix dashboard grid thumbnails cache invalidation.
This commit is contained in:
parent
7afb3e2c6d
commit
eb4e7e0f0c
2 changed files with 35 additions and 27 deletions
|
@ -165,6 +165,7 @@
|
||||||
f.created_at,
|
f.created_at,
|
||||||
f.modified_at,
|
f.modified_at,
|
||||||
f.name,
|
f.name,
|
||||||
|
f.revn,
|
||||||
f.is_shared
|
f.is_shared
|
||||||
from file as f
|
from file as f
|
||||||
where f.project_id = ?
|
where f.project_id = ?
|
||||||
|
@ -214,9 +215,6 @@
|
||||||
(some-> (retrieve-file cfg id)
|
(some-> (retrieve-file cfg id)
|
||||||
(assoc :permissions perms)))))
|
(assoc :permissions perms)))))
|
||||||
|
|
||||||
(s/def ::page
|
|
||||||
(s/keys :req-un [::profile-id ::file-id]))
|
|
||||||
|
|
||||||
(defn remove-thumbnails-frames
|
(defn remove-thumbnails-frames
|
||||||
"Removes from data the children for frames that have a thumbnail set up"
|
"Removes from data the children for frames that have a thumbnail set up"
|
||||||
[data]
|
[data]
|
||||||
|
@ -244,7 +242,12 @@
|
||||||
|
|
||||||
(update data :objects update-objects)))
|
(update data :objects update-objects)))
|
||||||
|
|
||||||
|
(s/def ::page
|
||||||
|
(s/keys :req-un [::profile-id ::file-id]))
|
||||||
|
|
||||||
(sv/defmethod ::page
|
(sv/defmethod ::page
|
||||||
|
"Retrieves the first page of the file. Used mainly for render
|
||||||
|
thumbnails on dashboard."
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id file-id strip-thumbnails]}]
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id strip-thumbnails]}]
|
||||||
(db/with-atomic [conn pool]
|
(db/with-atomic [conn pool]
|
||||||
(check-read-permissions! conn profile-id file-id)
|
(check-read-permissions! conn profile-id file-id)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(ns app.main.ui.dashboard.grid
|
(ns app.main.ui.dashboard.grid
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.logging :as log]
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
[app.main.data.dashboard :as dd]
|
[app.main.data.dashboard :as dd]
|
||||||
[app.main.data.messages :as dm]
|
[app.main.data.messages :as dm]
|
||||||
|
@ -30,6 +31,8 @@
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
|
(log/set-level! :warn)
|
||||||
|
|
||||||
;; --- Grid Item Thumbnail
|
;; --- Grid Item Thumbnail
|
||||||
|
|
||||||
(def ^:const CACHE-NAME "penpot")
|
(def ^:const CACHE-NAME "penpot")
|
||||||
|
@ -40,9 +43,10 @@
|
||||||
[file]
|
[file]
|
||||||
|
|
||||||
(let [cache-url (str CACHE-URL (:id file) "/" (:revn file) ".svg")
|
(let [cache-url (str CACHE-URL (:id file) "/" (:revn file) ".svg")
|
||||||
|
|
||||||
get-thumbnail
|
get-thumbnail
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps file)
|
(mf/deps cache-url)
|
||||||
(fn []
|
(fn []
|
||||||
(p/let [response (.match js/caches cache-url)]
|
(p/let [response (.match js/caches cache-url)]
|
||||||
(when (some? response)
|
(when (some? response)
|
||||||
|
@ -58,22 +62,24 @@
|
||||||
|
|
||||||
cache-thumbnail
|
cache-thumbnail
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps file)
|
(mf/deps cache-url)
|
||||||
(fn [{:keys [svg fonts]}]
|
(fn [{:keys [svg fonts]}]
|
||||||
(p/let [cache (.open js/caches CACHE-NAME)
|
(p/let [cache (.open js/caches CACHE-NAME)
|
||||||
blob (js/Blob. #js [svg] #js {:type "image/svg"})
|
blob (js/Blob. #js [svg] #js {:type "image/svg"})
|
||||||
fonts (str/join "," fonts)
|
fonts (str/join "," fonts)
|
||||||
headers (js/Headers. #js {"X-PENPOT-FONTS" fonts})
|
headers (js/Headers. #js {"X-PENPOT-FONTS" fonts})
|
||||||
response (js/Response. blob #js {:headers headers})]
|
response (js/Response. blob #js {:headers headers})]
|
||||||
(.put cache cache-url response))))
|
(.put cache cache-url response))))]
|
||||||
|
|
||||||
generate-thumbnail
|
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps file)
|
(mf/deps (:id file) (:revn file))
|
||||||
(fn []
|
(fn []
|
||||||
(->> (rx/from (get-thumbnail))
|
(->> (rx/from (get-thumbnail))
|
||||||
(rx/merge-map
|
(rx/merge-map
|
||||||
(fn [thumb-data]
|
(fn [thumb-data]
|
||||||
|
(log/debug :msg "retrieve thumbnail" :file (:id file) :revn (:revn file)
|
||||||
|
:cache (if (some? thumb-data) :hit :miss))
|
||||||
|
|
||||||
(if (some? thumb-data)
|
(if (some? thumb-data)
|
||||||
(rx/of thumb-data)
|
(rx/of thumb-data)
|
||||||
(->> (wrk/ask! {:cmd :thumbnails/generate
|
(->> (wrk/ask! {:cmd :thumbnails/generate
|
||||||
|
@ -84,24 +90,23 @@
|
||||||
;; If we have a problem we delegate to the thumbnail generation
|
;; If we have a problem we delegate to the thumbnail generation
|
||||||
(rx/catch #(wrk/ask! {:cmd :thumbnails/generate
|
(rx/catch #(wrk/ask! {:cmd :thumbnails/generate
|
||||||
:file-id (:id file)
|
:file-id (:id file)
|
||||||
:page-id (get-in file [:data :pages 0])})))))]
|
:page-id (get-in file [:data :pages 0])})))))))
|
||||||
|
|
||||||
generate-thumbnail))
|
|
||||||
|
|
||||||
(mf/defc grid-item-thumbnail
|
(mf/defc grid-item-thumbnail
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [file] :as props}]
|
[{:keys [file] :as props}]
|
||||||
(let [container (mf/use-ref)
|
(let [container (mf/use-ref)
|
||||||
generate-thumbnail (use-thumbnail-cache file)]
|
generate (use-thumbnail-cache file)]
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(mf/deps file)
|
(mf/deps file)
|
||||||
(fn []
|
(fn []
|
||||||
(->> (generate-thumbnail)
|
(->> (generate)
|
||||||
(rx/subs (fn [{:keys [svg fonts]}]
|
(rx/subs (fn [{:keys [svg fonts]}]
|
||||||
(run! fonts/ensure-loaded! fonts)
|
(run! fonts/ensure-loaded! fonts)
|
||||||
(when-let [node (mf/ref-val container)]
|
(when-let [node (mf/ref-val container)]
|
||||||
(set! (.-innerHTML ^js node) svg)))))))
|
(dom/set-html! node svg)))))))
|
||||||
|
|
||||||
[:div.grid-item-th {:style {:background-color (get-in file [:data :options :background])}
|
[:div.grid-item-th {:style {:background-color (get-in file [:data :options :background])}
|
||||||
:ref container}
|
:ref container}
|
||||||
i/loader-pencil]))
|
i/loader-pencil]))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue