From b2dee8ca7528139f03e326f63d4cadc5a63c3259 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 21 May 2026 18:26:38 +0800 Subject: [PATCH] fix: guard graph transfer concurrency --- src/main/frontend/handler/db_based/sync.cljs | 85 +++++++++++++------ .../frontend/handler/db_based/sync_test.cljs | 84 ++++++++++++++++++ 2 files changed, 141 insertions(+), 28 deletions(-) diff --git a/src/main/frontend/handler/db_based/sync.cljs b/src/main/frontend/handler/db_based/sync.cljs index 2b49a83820..b642dad2dd 100644 --- a/src/main/frontend/handler/db_based/sync.cljs +++ b/src/main/frontend/handler/db_based/sync.cljs @@ -117,6 +117,24 @@ true (true? graph-e2ee?))) +(defn- active-graph-operation [] + (let [{:rtc/keys [downloading-graph-uuid uploading?]} @state/state] + (cond + downloading-graph-uuid + {:active-operation :download + :active-graph-uuid downloading-graph-uuid} + + (true? uploading?) + {:active-operation :upload}))) + +(defn- reject-graph-operation-in-progress + [requested-operation active-operation] + (p/rejected + (ex-info "graph operation already in progress" + (assoc active-operation + :type :db-sync/graph-operation-in-progress + :requested-operation requested-operation)))) + (defn- (if (and graph-uuid base) - (p/let [_ (js/Promise. user-handler/task--ensure-id&access-token) - graph (str config/db-version-prefix graph-name) - _ ( (if (and graph-uuid base) + (p/let [_ (js/Promise. user-handler/task--ensure-id&access-token) + graph (str config/db-version-prefix graph-name) + _ ( (p/let [_ (state/ (p/with-redefs [db-sync/http-base (fn [] "http://base") + user-handler/task--ensure-id&access-token (fn [resolve _reject] + (resolve true)) + state/ (p/with-redefs [db-sync/http-base (fn [] "http://base") + user-handler/task--ensure-id&access-token (fn [resolve _reject] + (resolve true)) + state/ (p/with-redefs [state/