🐛 Fix storage/pointer-map support issues on thumbnails and libs loading

This commit is contained in:
Andrey Antukh 2022-12-27 14:49:14 +01:00 committed by Alejandro Alonso
parent 84fd952471
commit 60fb3f3d0e
3 changed files with 47 additions and 37 deletions

View file

@ -241,7 +241,6 @@
[conn id client-features] [conn id client-features]
;; here we check if client requested features are supported ;; here we check if client requested features are supported
(check-features-compatibility! client-features) (check-features-compatibility! client-features)
(binding [pmap/*load-fn* (partial load-pointer conn id)] (binding [pmap/*load-fn* (partial load-pointer conn id)]
(-> (db/get-by-id conn :file id) (-> (db/get-by-id conn :file id)
(decode-row) (decode-row)
@ -533,12 +532,14 @@
[conn file-id client-features] [conn file-id client-features]
(check-features-compatibility! client-features) (check-features-compatibility! client-features)
(->> (db/exec! conn [sql:file-libraries file-id]) (->> (db/exec! conn [sql:file-libraries file-id])
(mapv (fn [{:keys [id] :as row}] (map decode-row)
(binding [pmap/*load-fn* (partial load-pointer conn id)] (map #(assoc % :is-indirect false))
(-> (decode-row row) (map (fn [{:keys [id] :as row}]
(assoc :is-indirect false) (binding [pmap/*load-fn* (partial load-pointer conn id)]
(update :data dissoc :pages-index) (-> row
(handle-file-features client-features))))))) (update :data dissoc :pages-index)
(handle-file-features client-features)))))
(vec)))
(s/def ::get-file-libraries (s/def ::get-file-libraries
(s/keys :req [::rpc/profile-id] (s/keys :req [::rpc/profile-id]
@ -708,28 +709,30 @@
objects)))] objects)))]
(let [frame (get-thumbnail-frame data) (binding [pmap/*load-fn* (partial load-pointer conn id)]
frame-id (:id frame) (let [frame (get-thumbnail-frame data)
page-id (or (:page-id frame) frame-id (:id frame)
(-> data :pages first)) page-id (or (:page-id frame)
(-> data :pages first))
page (dm/get-in data [:pages-index page-id]) page (dm/get-in data [:pages-index page-id])
frame-ids (if (some? frame) (list frame-id) (map :id (ctt/get-frames (:objects page)))) page (cond-> page (pmap/pointer-map? page) deref)
frame-ids (if (some? frame) (list frame-id) (map :id (ctt/get-frames (:objects page))))
obj-ids (map #(str page-id %) frame-ids) obj-ids (map #(str page-id %) frame-ids)
thumbs (get-object-thumbnails conn id obj-ids)] thumbs (get-object-thumbnails conn id obj-ids)]
(cond-> page (cond-> page
;; If we have frame, we need to specify it on the page level ;; If we have frame, we need to specify it on the page level
;; and remove the all other unrelated objects. ;; and remove the all other unrelated objects.
(some? frame-id) (some? frame-id)
(-> (assoc :thumbnail-frame-id frame-id) (-> (assoc :thumbnail-frame-id frame-id)
(update :objects filter-objects frame-id)) (update :objects filter-objects frame-id))
;; Assoc the available thumbnails and prune not visible shapes ;; Assoc the available thumbnails and prune not visible shapes
;; for avoid transfer unnecessary data. ;; for avoid transfer unnecessary data.
:always :always
(update :objects assoc-thumbnails page-id thumbs))))) (update :objects assoc-thumbnails page-id thumbs))))))
(s/def ::get-file-data-for-thumbnail (s/def ::get-file-data-for-thumbnail
(s/keys :req [::rpc/profile-id] (s/keys :req [::rpc/profile-id]
@ -743,12 +746,15 @@
[{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id features] :as props}] [{:keys [pool] :as cfg} {:keys [::rpc/profile-id file-id features] :as props}]
(with-open [conn (db/open pool)] (with-open [conn (db/open pool)]
(check-read-permissions! conn profile-id file-id) (check-read-permissions! conn profile-id file-id)
(let [file (get-file conn file-id features)] ;; NOTE: we force here the "storage/pointer-map" feature, because
;; it used internally only and is independent if user supports it
;; or not.
(let [feat (into #{"storage/pointer-map"} features)
file (get-file conn file-id feat)]
{:file-id file-id {:file-id file-id
:revn (:revn file) :revn (:revn file)
:page (get-file-data-for-thumbnail conn file)}))) :page (get-file-data-for-thumbnail conn file)})))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MUTATION COMMANDS ;; MUTATION COMMANDS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -150,14 +150,15 @@
(defn- bundle-fetched (defn- bundle-fetched
[features [{:keys [id data] :as file} thumbnails project users comments-users]] [features [{:keys [id data] :as file} thumbnails project users comments-users]]
(letfn [(resolve-pointer [[key pointer]] (letfn [(resolve-pointer [file-id [key pointer]]
(->> (rp/cmd! :get-file-fragment {:file-id id :fragment-id @pointer}) (->> (rp/cmd! :get-file-fragment {:file-id file-id :fragment-id @pointer})
(rx/map :content) (rx/map :content)
(rx/map #(vector key %)))) (rx/map #(vector key %))))
(resolve-pointers [in-to coll]
(resolve-pointers [file-id coll]
(->> (rx/from (seq coll)) (->> (rx/from (seq coll))
(rx/merge-map resolve-pointer) (rx/merge-map (partial resolve-pointer file-id))
(rx/reduce conj in-to)))] (rx/reduce conj {})))]
(ptk/reify ::bundle-fetched (ptk/reify ::bundle-fetched
ptk/UpdateEvent ptk/UpdateEvent
@ -186,7 +187,7 @@
(rx/merge-map (rx/merge-map
(fn [[_ page :as kp]] (fn [[_ page :as kp]]
(if (t/pointer? page) (if (t/pointer? page)
(resolve-pointer kp) (resolve-pointer id kp)
(rx/of kp)))) (rx/of kp))))
(rx/merge-map (rx/merge-map
(fn [[id page]] (fn [[id page]]
@ -212,15 +213,17 @@
(->> data (->> data
(filter (comp t/pointer? val)) (filter (comp t/pointer? val))
(resolve-pointers {}) (resolve-pointers id)
(rx/map workspace-data-pointers-loaded)) (rx/map workspace-data-pointers-loaded))
(->> (rp/cmd! :get-file-libraries {:file-id id :features features}) (->> (rp/cmd! :get-file-libraries {:file-id id :features features})
(rx/mapcat identity) (rx/mapcat identity)
(rx/mapcat (rx/mapcat
(fn [file] (fn [{:keys [id data] :as file}]
(->> (filter (comp t/pointer? val) file) (->> (filter (comp t/pointer? val) data)
(resolve-pointers file)))) (resolve-pointers id)
(rx/map #(update file :data merge %)))))
(rx/reduce conj [])
(rx/map libraries-fetched))))))) (rx/map libraries-fetched)))))))
(rx/take-until stoper))))))) (rx/take-until stoper)))))))

View file

@ -22,6 +22,7 @@
(derive :get-team-members ::query) (derive :get-team-members ::query)
(derive :get-team-stats ::query) (derive :get-team-stats ::query)
(derive :get-team-invitations ::query) (derive :get-team-invitations ::query)
(derive :get-team-shared-files ::query)
(defn handle-response (defn handle-response
[{:keys [status body] :as response}] [{:keys [status body] :as response}]