0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

Cache rasterizer resources

This commit is contained in:
Aitor 2023-11-29 15:27:17 +01:00 committed by Andrey Antukh
parent aa6fdf10f9
commit f477de962d

View file

@ -25,6 +25,8 @@
(declare send-success!) (declare send-success!)
(declare send-failure!) (declare send-failure!)
(defonce data-uri-cache (js/Map.))
(defonce parent-origin (defonce parent-origin
(dm/str cf/public-uri)) (dm/str cf/public-uri))
@ -86,13 +88,18 @@
(defn- fetch-as-data-uri (defn- fetch-as-data-uri
"Fetches a URL as a Data URI." "Fetches a URL as a Data URI."
[uri] [uri]
(->> (http/send! {:uri uri (if (.has data-uri-cache uri)
:response-type :blob (let [blob (.get data-uri-cache uri)]
:method :get (rx/from (.text blob)))
:mode :cors (->> (http/send! {:uri uri
:omit-default-headers true}) :response-type :blob
(rx/map :body) :method :get
(rx/mapcat wapi/read-file-as-data-url))) :mode :cors
:omit-default-headers true})
(rx/map :body)
(rx/mapcat wapi/read-file-as-data-url)
(rx/tap (fn [data-uri]
(.set data-uri-cache uri (wapi/create-blob data-uri "text/plain")))))))
(defn- svg-update-image! (defn- svg-update-image!
"Updates an image in an SVG to a Data URI." "Updates an image in an SVG to a Data URI."