mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
fix: ensure all graphs are latest in those cases
1. upload a local graph 2. download a local graph 3. a remote graph has been deleted from another client
This commit is contained in:
@@ -126,7 +126,9 @@
|
||||
(repo-handler/remove-repo! repo)
|
||||
(state/pub-event! [:graph/unlinked repo (state/get-current-repo)]))))))}
|
||||
"Delete local graph"))
|
||||
(when (and db-based? root (not remote?))
|
||||
(when (and db-based? root
|
||||
(not remote?)
|
||||
(= url (state/get-current-repo)))
|
||||
(shui/dropdown-menu-item
|
||||
{:key "logseq-sync"
|
||||
:class "use-logseq-sync-menu-item"
|
||||
@@ -141,11 +143,14 @@
|
||||
(shui/popup-show! nil
|
||||
(fn []
|
||||
(rtc-indicator/uploading-logs))
|
||||
{:id :rtc-graph-upload-log})
|
||||
(rtc-indicator/on-upload-finished-task
|
||||
(fn []
|
||||
(shui/popup-hide! :rtc-graph-upload-log)
|
||||
(rtc-flows/trigger-rtc-start repo)))))))}
|
||||
{:id :rtc-graph-upload-log}))
|
||||
|
||||
(rtc-indicator/on-upload-finished-task
|
||||
(fn []
|
||||
(when (util/mobile?) (shui/popup-hide! :rtc-graph-upload-log))
|
||||
(p/do!
|
||||
(rtc-flows/trigger-rtc-start repo)
|
||||
(rtc-handler/<get-remote-graphs)))))))}
|
||||
"Use Logseq sync (Beta testing)"))
|
||||
(when (and remote? (or (and db-based? manager?) (not db-based?)))
|
||||
(shui/dropdown-menu-item
|
||||
@@ -165,9 +170,12 @@
|
||||
(fn [graph-uuid _graph-schema-version]
|
||||
(async-util/c->p (file-sync/<delete-graph graph-uuid))))]
|
||||
(state/set-state! [:file-sync/remote-graphs :loading] true)
|
||||
(when (= (state/get-current-repo) repo)
|
||||
(state/<invoke-db-worker :thread-api/rtc-stop))
|
||||
(p/do! (<delete-graph GraphUUID GraphSchemaVersion)
|
||||
(state/delete-remote-graph! repo)
|
||||
(state/set-state! [:file-sync/remote-graphs :loading] false)))))))))}
|
||||
(state/set-state! [:file-sync/remote-graphs :loading] false)
|
||||
(rtc-handler/<get-remote-graphs)))))))))}
|
||||
"Delete from server")))))]]]))
|
||||
|
||||
(rum/defc repos-cp < rum/reactive
|
||||
@@ -228,9 +236,7 @@
|
||||
:on-click (fn []
|
||||
(when-not (util/capacitor-new?)
|
||||
(file-sync/load-session-graphs))
|
||||
(p/do!
|
||||
(rtc-handler/<get-remote-graphs)
|
||||
(repo-handler/refresh-repos!))))]]
|
||||
(rtc-handler/<get-remote-graphs)))]]
|
||||
(repos-inner remote-graphs)])]]))
|
||||
|
||||
(defn- repos-dropdown-links [repos current-repo downloading-graph-id & {:as opts}]
|
||||
@@ -465,8 +471,7 @@
|
||||
(state/set-state! :rtc/uploading? true)
|
||||
(rtc-handler/<rtc-create-graph! repo)
|
||||
(rtc-flows/trigger-rtc-start repo)
|
||||
(rtc-handler/<get-remote-graphs)
|
||||
(repo-handler/refresh-repos!))
|
||||
(rtc-handler/<get-remote-graphs))
|
||||
(p/catch (fn [error]
|
||||
(log/error :create-db-failed error)))
|
||||
(p/finally (fn []
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
[frontend.db :as db]
|
||||
[frontend.handler.db-based.rtc-flows :as rtc-flows]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.handler.repo :as repo-handler]
|
||||
[frontend.handler.user :as user-handler]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
@@ -145,7 +146,8 @@
|
||||
:GraphUUID (:graph-uuid graph)
|
||||
:rtc-graph? true})
|
||||
(dissoc graph :graph-uuid :graph-name)))))]
|
||||
(state/set-state! :rtc/graphs result)))
|
||||
(state/set-state! :rtc/graphs result)
|
||||
(repo-handler/refresh-repos!)))
|
||||
|
||||
(defn <rtc-get-users-info
|
||||
[]
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[frontend.flows :as flows]
|
||||
[frontend.mobile.flows :as mobile-flows]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
[logseq.common.util :as common-util]
|
||||
[missionary.core :as m])
|
||||
(:import [missionary Cancelled]))
|
||||
|
||||
@@ -376,6 +376,11 @@
|
||||
(defmethod handle :rtc/log [[_ data]]
|
||||
(state/set-state! :rtc/log data))
|
||||
|
||||
(defmethod handle :rtc/remote-graph-gone [_]
|
||||
(p/do!
|
||||
(notification/show! "This graph has been removed from Logseq Sync." :warning false)
|
||||
(rtc-handler/<get-remote-graphs)))
|
||||
|
||||
(defmethod handle :rtc/download-remote-graph [[_ graph-name graph-uuid graph-schema-version]]
|
||||
(assert (= (:major (db-schema/parse-schema-version db-schema/version))
|
||||
(:major (db-schema/parse-schema-version graph-schema-version)))
|
||||
@@ -393,7 +398,6 @@
|
||||
{:id :download-rtc-graph}))
|
||||
(rtc-handler/<rtc-download-graph! graph-name graph-uuid graph-schema-version 60000)
|
||||
(rtc-handler/<get-remote-graphs)
|
||||
(repo-handler/refresh-repos!)
|
||||
(when (util/mobile?)
|
||||
(shui/popup-hide! :download-rtc-graph)))
|
||||
(p/catch (fn [e]
|
||||
|
||||
@@ -55,6 +55,9 @@
|
||||
(defmethod handle :notify-existing-file [_ _worker data]
|
||||
(state/pub-event! [:graph/notify-existing-file data]))
|
||||
|
||||
(defmethod handle :remote-graph-gone []
|
||||
(state/pub-event! [:rtc/remote-graph-gone]))
|
||||
|
||||
(defmethod handle :default [_ _worker data]
|
||||
(prn :debug "Worker data not handled: " data))
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@
|
||||
[repo graph-uuid]
|
||||
{:pre [(some? graph-uuid)]}
|
||||
(when-let [conn (worker-state/get-client-ops-conn repo)]
|
||||
(assert (nil? (first (d/datoms @conn :avet :graph-uuid))))
|
||||
(d/transact! conn [[:db/add "e" :graph-uuid graph-uuid]])))
|
||||
|
||||
(defn get-graph-uuid
|
||||
@@ -470,13 +469,3 @@
|
||||
(m/ap
|
||||
(let [_ (m/?> (c.m/throttle 100 db-updated-flow))]
|
||||
(datom-count-fn @conn))))))
|
||||
|
||||
(defn reset-client-op-conn
|
||||
[repo]
|
||||
(when-let [conn (worker-state/get-client-ops-conn repo)]
|
||||
(let [tx-data (->> (concat (d/datoms @conn :avet :graph-uuid)
|
||||
(d/datoms @conn :avet :local-tx)
|
||||
(d/datoms @conn :avet :aes-key-jwk)
|
||||
(d/datoms @conn :avet :block/uuid))
|
||||
(map (fn [datom] [:db/retractEntity (:e datom)])))]
|
||||
(d/transact! conn tx-data))))
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
[frontend.worker.rtc.branch-graph :as r.branch-graph]
|
||||
[frontend.worker.rtc.client :as r.client]
|
||||
[frontend.worker.rtc.client-op :as client-op]
|
||||
[frontend.worker.rtc.db :as rtc-db]
|
||||
[frontend.worker.rtc.exception :as r.ex]
|
||||
[frontend.worker.rtc.full-upload-download-graph :as r.upload-download]
|
||||
[frontend.worker.rtc.log-and-state :as rtc-log-and-state]
|
||||
@@ -370,7 +371,9 @@
|
||||
(log/info :rtc-loop-task e)))
|
||||
start-ex (m/? onstarted-task)]
|
||||
(if (instance? ExceptionInfo start-ex)
|
||||
start-ex
|
||||
(do
|
||||
(canceler)
|
||||
start-ex)
|
||||
(do (reset! *rtc-loop-metadata {:repo repo
|
||||
:graph-uuid graph-uuid
|
||||
:local-graph-schema-version schema-version
|
||||
@@ -442,7 +445,14 @@
|
||||
{:action "delete-graph"
|
||||
:graph-uuid graph-uuid
|
||||
:schema-version (str schema-version)}))]
|
||||
(when ex-data (log/info ::delete-graph-failed {:graph-uuid graph-uuid :ex-data ex-data}))
|
||||
(if ex-data
|
||||
(log/info ::delete-graph-failed {:graph-uuid graph-uuid :ex-data ex-data})
|
||||
;; Clean up rtc data in existing dbs so that the graph can be uploaded again
|
||||
(when-let [repo (worker-state/get-current-repo)]
|
||||
(when-let [conn (worker-state/get-datascript-conn repo)]
|
||||
(let [graph-id (ldb/get-graph-rtc-uuid @conn)]
|
||||
(when (= (str graph-id) (str graph-uuid))
|
||||
(rtc-db/remove-rtc-data-in-conn! repo))))))
|
||||
(boolean (nil? ex-data))))))
|
||||
|
||||
(defn new-task--get-users-info
|
||||
|
||||
26
src/main/frontend/worker/rtc/db.cljs
Normal file
26
src/main/frontend/worker/rtc/db.cljs
Normal file
@@ -0,0 +1,26 @@
|
||||
(ns frontend.worker.rtc.db
|
||||
"rtc db ops"
|
||||
(:require [datascript.core :as d]
|
||||
[frontend.worker.state :as worker-state]))
|
||||
|
||||
(defn remove-rtc-data-from-local-db!
|
||||
[repo]
|
||||
(when-let [conn (worker-state/get-datascript-conn repo)]
|
||||
(d/transact! conn [[:db/retractEntity :logseq.kv/graph-uuid]
|
||||
[:db/retractEntity :logseq.kv/graph-local-tx]
|
||||
[:db/retractEntity :logseq.kv/remote-schema-version]])))
|
||||
|
||||
(defn reset-client-op-conn
|
||||
[repo]
|
||||
(when-let [conn (worker-state/get-client-ops-conn repo)]
|
||||
(let [tx-data (->> (concat (d/datoms @conn :avet :graph-uuid)
|
||||
(d/datoms @conn :avet :local-tx)
|
||||
(d/datoms @conn :avet :aes-key-jwk)
|
||||
(d/datoms @conn :avet :block/uuid))
|
||||
(map (fn [datom] [:db/retractEntity (:e datom)])))]
|
||||
(d/transact! conn tx-data))))
|
||||
|
||||
(defn remove-rtc-data-in-conn!
|
||||
[repo]
|
||||
(remove-rtc-data-from-local-db! repo)
|
||||
(reset-client-op-conn repo))
|
||||
@@ -11,6 +11,7 @@
|
||||
[frontend.worker.db-metadata :as worker-db-metadata]
|
||||
[frontend.worker.rtc.client-op :as client-op]
|
||||
[frontend.worker.rtc.const :as rtc-const]
|
||||
[frontend.worker.rtc.db :as rtc-db]
|
||||
[frontend.worker.rtc.log-and-state :as rtc-log-and-state]
|
||||
[frontend.worker.rtc.ws-util :as ws-util]
|
||||
[frontend.worker.shared-service :as shared-service]
|
||||
@@ -120,14 +121,6 @@
|
||||
(:db/ident block) (update :db/ident ldb/read-transit-str)
|
||||
(:block/order block) (update :block/order ldb/read-transit-str)))))))
|
||||
|
||||
(defn- remove-rtc-data-in-conn!
|
||||
[repo]
|
||||
(client-op/reset-client-op-conn repo)
|
||||
(when-let [conn (worker-state/get-datascript-conn repo)]
|
||||
(d/transact! conn [[:db/retractEntity :logseq.kv/graph-uuid]
|
||||
[:db/retractEntity :logseq.kv/graph-local-tx]
|
||||
[:db/retractEntity :logseq.kv/remote-schema-version]])))
|
||||
|
||||
(defn new-task--upload-graph
|
||||
[get-ws-create-task repo conn remote-graph-name major-schema-version]
|
||||
(m/sp
|
||||
@@ -477,7 +470,7 @@
|
||||
(m/sp
|
||||
(rtc-log-and-state/rtc-log :rtc.log/branch-graph {:sub-type :fetching-presigned-put-url
|
||||
:message "fetching presigned put-url"})
|
||||
(remove-rtc-data-in-conn! repo)
|
||||
(rtc-db/remove-rtc-data-in-conn! repo)
|
||||
(let [[{:keys [url key]} all-blocks-str]
|
||||
(m/?
|
||||
(m/join
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
(ns frontend.worker.rtc.ws-util
|
||||
"Add RTC related logic to the function based on ws."
|
||||
(:require [cljs-http-missionary.client :as http]
|
||||
[frontend.worker.rtc.db :as rtc-db]
|
||||
[frontend.worker.rtc.exception :as r.ex]
|
||||
[frontend.worker.rtc.malli-schema :as rtc-schema]
|
||||
[frontend.worker.rtc.ws :as ws]
|
||||
[frontend.worker.state :as worker-state]
|
||||
[frontend.worker.util :as worker-util]
|
||||
[goog.string :as gstring]
|
||||
[logseq.graph-parser.utf8 :as utf8]
|
||||
[missionary.core :as m]))
|
||||
|
||||
(defn- handle-remote-ex
|
||||
[resp]
|
||||
(when (= :graph-not-exist (:type (:ex-data resp)))
|
||||
(rtc-db/remove-rtc-data-in-conn! (worker-state/get-current-repo))
|
||||
(worker-util/post-message :remote-graph-gone []))
|
||||
(if-let [e ({:graph-not-exist r.ex/ex-remote-graph-not-exist
|
||||
:graph-not-ready r.ex/ex-remote-graph-not-ready
|
||||
:bad-request-body r.ex/ex-bad-request-body
|
||||
|
||||
Reference in New Issue
Block a user