refactor(db-sync): rename worker-sync to db-sync

This commit is contained in:
rcmerci
2026-01-10 17:52:33 +08:00
parent cdd380bdc7
commit 0864b485f4
35 changed files with 199 additions and 199 deletions

View File

@@ -1,5 +1,5 @@
(ns frontend.handler.db-based.worker-sync
"Worker-sync handler based on Cloudflare Durable Objects."
(ns frontend.handler.db-based.db-sync
"DB-sync handler based on Cloudflare Durable Objects."
(:require [clojure.string :as string]
[frontend.config :as config]
[frontend.db :as db]
@@ -26,8 +26,8 @@
base)))
(defn- http-base []
(or config/worker-sync-http-base
(ws->http-base config/worker-sync-ws-url)))
(or config/db-sync-http-base
(ws->http-base config/db-sync-ws-url)))
(def ^:private snapshot-rows-limit 2000)
@@ -47,20 +47,20 @@
data (when (seq text) (js/JSON.parse text))]
(if (.-ok resp)
data
(throw (ex-info "worker-sync request failed"
(throw (ex-info "db-sync request failed"
{:status (.-status resp)
:url url
:body data})))))
(defn <rtc-start!
[repo & {:keys [_stop-before-start?] :as _opts}]
(log/info :worker-sync/start {:repo repo})
(state/<invoke-db-worker :thread-api/worker-sync-start repo))
(log/info :db-sync/start {:repo repo})
(state/<invoke-db-worker :thread-api/db-sync-start repo))
(defn <rtc-stop!
[]
(log/info :worker-sync/stop true)
(state/<invoke-db-worker :thread-api/worker-sync-stop))
(log/info :db-sync/stop true)
(state/<invoke-db-worker :thread-api/db-sync-stop))
(defn <rtc-get-users-info
[]
@@ -84,11 +84,11 @@
(ldb/transact! repo [(sqlite-util/kv :logseq.kv/db-type "db")
(sqlite-util/kv :logseq.kv/graph-uuid (uuid graph-id))])
graph-id)
(p/rejected (ex-info "worker-sync missing graph id in create response"
{:type :worker-sync/invalid-graph
(p/rejected (ex-info "db-sync missing graph id in create response"
{:type :db-sync/invalid-graph
:response result}))))
(p/rejected (ex-info "worker-sync missing graph info"
{:type :worker-sync/invalid-graph
(p/rejected (ex-info "db-sync missing graph info"
{:type :db-sync/invalid-graph
:base base})))))
(defn <rtc-delete-graph!
@@ -97,8 +97,8 @@
(if (and graph-uuid base)
(p/let [_ (js/Promise. user-handler/task--ensure-id&access-token)]
(fetch-json (str base "/graphs/" graph-uuid) {:method "DELETE"}))
(p/rejected (ex-info "worker-sync missing graph id"
{:type :worker-sync/invalid-graph
(p/rejected (ex-info "db-sync missing graph id"
{:type :db-sync/invalid-graph
:graph-uuid graph-uuid
:base base})))))
@@ -125,13 +125,13 @@
done? (true? (aget resp "done"))
last-addr (or (aget resp "last_addr") after)]
(p/do!
(state/<invoke-db-worker :thread-api/worker-sync-import-kvs-rows
(state/<invoke-db-worker :thread-api/db-sync-import-kvs-rows
graph rows first-batch?)
(if done?
(state/<invoke-db-worker :thread-api/worker-sync-finalize-kvs-import graph remote-tx)
(state/<invoke-db-worker :thread-api/db-sync-finalize-kvs-import graph remote-tx)
(p/recur last-addr false))))))
(p/rejected (ex-info "worker-sync missing graph info"
{:type :worker-sync/invalid-graph
(p/rejected (ex-info "db-sync missing graph info"
{:type :db-sync/invalid-graph
:graph-uuid graph-uuid
:base base})))
(p/catch (fn [error]

View File

@@ -1,34 +1,34 @@
(ns frontend.handler.db-based.sync
"Dispatch RTC calls between legacy RTC and worker-sync implementations."
"Dispatch RTC calls between legacy RTC and db-sync implementations."
(:require [frontend.config :as config]
[frontend.db :as db]
[frontend.handler.db-based.rtc :as rtc-handler]
[frontend.handler.db-based.worker-sync :as worker-sync-handler]
[frontend.handler.db-based.db-sync :as db-sync-handler]
[frontend.state :as state]
[logseq.db :as ldb]
[promesa.core :as p]))
(defn- worker-sync-enabled? []
config/worker-sync-enabled?)
(defn- db-sync-enabled? []
config/db-sync-enabled?)
(defn <rtc-create-graph! [repo]
(if (worker-sync-enabled?)
(worker-sync-handler/<rtc-create-graph! repo)
(if (db-sync-enabled?)
(db-sync-handler/<rtc-create-graph! repo)
(rtc-handler/<rtc-create-graph! repo)))
(defn <rtc-delete-graph! [graph-uuid schema-version]
(if (worker-sync-enabled?)
(worker-sync-handler/<rtc-delete-graph! graph-uuid schema-version)
(if (db-sync-enabled?)
(db-sync-handler/<rtc-delete-graph! graph-uuid schema-version)
(rtc-handler/<rtc-delete-graph! graph-uuid schema-version)))
(defn <rtc-download-graph! [graph-name graph-uuid graph-schema-version timeout-ms]
(if (worker-sync-enabled?)
(worker-sync-handler/<rtc-download-graph! graph-name graph-uuid graph-schema-version)
(if (db-sync-enabled?)
(db-sync-handler/<rtc-download-graph! graph-name graph-uuid graph-schema-version)
(rtc-handler/<rtc-download-graph! graph-name graph-uuid graph-schema-version timeout-ms)))
(defn <rtc-stop! []
(if (worker-sync-enabled?)
(worker-sync-handler/<rtc-stop!)
(if (db-sync-enabled?)
(db-sync-handler/<rtc-stop!)
(rtc-handler/<rtc-stop!)))
(defn <rtc-branch-graph! [repo]
@@ -38,30 +38,30 @@
(rtc-handler/notification-download-higher-schema-graph! graph-name graph-uuid schema-version))
(defn <rtc-get-users-info []
(if (worker-sync-enabled?)
(worker-sync-handler/<rtc-get-users-info)
(if (db-sync-enabled?)
(db-sync-handler/<rtc-get-users-info)
(rtc-handler/<rtc-get-users-info)))
(defn <rtc-start!
[repo & {:keys [stop-before-start?] :or {stop-before-start? true}}]
(if (worker-sync-enabled?)
(worker-sync-handler/<rtc-start! repo :stop-before-start? stop-before-start?)
(if (db-sync-enabled?)
(db-sync-handler/<rtc-start! repo :stop-before-start? stop-before-start?)
(rtc-handler/<rtc-start! repo :stop-before-start? stop-before-start?)))
(defn <rtc-upload-graph! [repo token remote-graph-name]
(if (worker-sync-enabled?)
(p/let [graph-id (worker-sync-handler/<rtc-create-graph! repo)]
(if (db-sync-enabled?)
(p/let [graph-id (db-sync-handler/<rtc-create-graph! repo)]
(when (nil? graph-id)
(throw (ex-info "graph id doesn't exist when uploading to server" {:repo repo})))
(p/do!
(state/<invoke-db-worker :thread-api/worker-sync-upload-graph repo)
(state/<invoke-db-worker :thread-api/db-sync-upload-graph repo)
(<rtc-start! repo)))
(state/<invoke-db-worker :thread-api/rtc-async-upload-graph
repo token remote-graph-name)))
(defn <get-remote-graphs []
(if (worker-sync-enabled?)
(worker-sync-handler/<get-remote-graphs)
(if (db-sync-enabled?)
(db-sync-handler/<get-remote-graphs)
(rtc-handler/<get-remote-graphs)))
(defn <rtc-invite-email [graph-uuid email]