Skip to content

Commit

Permalink
enhance(asset-sync): add log
Browse files Browse the repository at this point in the history
  • Loading branch information
RCmerci authored and tiensonqin committed Nov 25, 2024
1 parent 909d90c commit 429cb7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/main/frontend/worker/rtc/asset.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
(client-op/remove-asset-op repo asset-uuid)))

(defn- new-task--push-local-asset-updates
[repo get-ws-create-task conn graph-uuid _add-log-fn]
[repo get-ws-create-task conn graph-uuid add-log-fn]
(m/sp
(when-let [asset-ops (not-empty (client-op/get-all-asset-ops repo))]
(let [upload-asset-uuids (keep
Expand Down Expand Up @@ -162,8 +162,9 @@
[asset-uuid {"checksum" checksum "type" asset-type}]))
asset-uuid->asset-type+checksum)}))
:asset-uuid->url))]
(when (seq asset-uuid->url)
(add-log-fn :rtc.asset.log/upload-assets {:asset-uuids (keys asset-uuid->url)}))
(doseq [[asset-uuid put-url] asset-uuid->url]
(prn :start-upload-asset asset-uuid)
(let [[asset-type checksum] (get asset-uuid->asset-type+checksum asset-uuid)
r (ldb/read-transit-str
(c.m/<?
Expand All @@ -179,7 +180,7 @@
{:persist-op? false})
(client-op/remove-asset-op repo asset-uuid)))
(when (seq remove-asset-uuids)
(prn :start-delete-assets remove-asset-uuids)
(add-log-fn :rtc.asset.log/remove-assets {:asset-uuids remove-asset-uuids})
(m/? (ws-util/send&recv get-ws-create-task
{:action "delete-assets"
:graph-uuid graph-uuid
Expand All @@ -191,7 +192,7 @@
(concat (keys asset-uuid->url) remove-asset-uuids))))))

(defn- new-task--pull-remote-asset-updates
[repo get-ws-create-task conn graph-uuid _add-log-fn asset-update-ops]
[repo get-ws-create-task conn graph-uuid add-log-fn asset-update-ops]
(m/sp
(when (seq asset-update-ops)
(let [update-asset-uuids (keep (fn [op]
Expand All @@ -218,6 +219,8 @@
:asset-uuid->url))]
(doseq [[asset-uuid asset-type] remove-asset-uuid->asset-type]
(c.m/<? (.unlinkAsset ^js @worker-state/*main-thread repo (str asset-uuid) asset-type)))
(when (seq asset-uuid->url)
(add-log-fn :rtc.asset.log/download-assets {:asset-uuids (keys asset-uuid->url)}))
(doseq [[asset-uuid get-url] asset-uuid->url]
(prn :start-download-asset asset-uuid)
(let [r (ldb/read-transit-str
Expand Down Expand Up @@ -252,6 +255,7 @@
(not-empty
(map (fn [asset-uuid] {:op :update-asset :block/uuid asset-uuid})
(set/difference local-all-asset-uuids local-all-asset-file-uuids)))]
(add-log-fn :rtc.asset.log/initial-download-missing-assets-count {:count (count asset-update-ops)})
(m/? (new-task--pull-remote-asset-updates
repo get-ws-create-task conn graph-uuid add-log-fn asset-update-ops))))))

Expand Down
6 changes: 5 additions & 1 deletion src/main/frontend/worker/rtc/log_and_state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
:rtc.log/apply-remote-update
:rtc.log/push-local-update

:rtc.asset.log/cancelled])
:rtc.asset.log/cancelled
:rtc.asset.log/upload-assets
:rtc.asset.log/download-assets
:rtc.asset.log/remove-assets
:rtc.asset.log/initial-download-missing-assets-count])

(def ^:private rtc-log-type-validator (ma/validator rtc-log-type-schema))

Expand Down

0 comments on commit 429cb7a

Please sign in to comment.