浏览代码

fix(asset): init upload all assets

rcmerci 10 月之前
父节点
当前提交
d60ddd3291

+ 20 - 0
src/main/frontend/worker/rtc/client_op.cljs

@@ -99,6 +99,12 @@
             [:db/add "e" :local-tx t])]
       (d/transact! conn [tx-data]))))
 
+(defn remove-local-tx
+  [repo]
+  (when-let [conn (worker-state/get-client-ops-conn repo)]
+    (when-let [datom (first (d/datoms @conn :avet :local-tx))]
+      (d/transact! conn [[:db/retract (:e datom) :local-tx]]))))
+
 (defn get-local-tx
   [repo]
   (when-let [conn (worker-state/get-client-ops-conn repo)]
@@ -298,6 +304,20 @@
                               update-asset-op (conj [:db.fn/retractAttribute e :update-asset]))))))]
             (d/transact! conn tx-data)))))))
 
+(defn add-all-exists-asset-as-ops
+  [repo]
+  (let [conn (worker-state/get-datascript-conn repo)
+        _ (assert (some? conn))
+        asset-block-uuids (d/q '[:find [?block-uuid ...]
+                                 :where
+                                 [?b :block/uuid ?block-uuid]
+                                 [?b :logseq.property.asset/type]]
+                               @conn)
+        ops (map
+             (fn [block-uuid] [:update-asset 1 {:block-uuid block-uuid}])
+             asset-block-uuids)]
+    (add-asset-ops repo ops)))
+
 (defn- get-all-asset-ops*
   [db]
   (->> (d/datoms db :eavt)

+ 2 - 0
src/main/frontend/worker/rtc/full_upload_download_graph.cljs

@@ -141,6 +141,8 @@
                            [{:db/ident :logseq.kv/graph-uuid :kv/value graph-uuid}
                             {:db/ident :logseq.kv/graph-local-tx :kv/value "0"}])
             (client-op/update-graph-uuid repo graph-uuid)
+            (client-op/remove-local-tx repo)
+            (client-op/add-all-exists-asset-as-ops repo)
             (crypt/store-graph-keys-jwk repo aes-key-jwk)
             (when-not rtc-const/RTC-E2E-TEST
               (let [^js worker-obj (:worker/object @worker-state/*state)]