mirror of
https://github.com/logseq/logseq.git
synced 2026-05-21 11:22:44 +00:00
enhance(rtc): rename ns frontend.worker.rtc.branch-graph, fix rtc malli-schema
This commit is contained in:
4
deps/db/src/logseq/db.cljs
vendored
4
deps/db/src/logseq/db.cljs
vendored
@@ -524,6 +524,10 @@
|
||||
[db]
|
||||
(when db (get-key-value db :logseq.kv/graph-uuid)))
|
||||
|
||||
(defn get-graph-schema-version
|
||||
[db]
|
||||
(when db (get-key-value db :logseq.kv/schema-version)))
|
||||
|
||||
;; File based fns
|
||||
(defn get-namespace-pages
|
||||
"Accepts both sanitized and unsanitized namespaces"
|
||||
|
||||
@@ -857,16 +857,6 @@
|
||||
(with-write-transit-str
|
||||
(js/Promise. (rtc-core/new-task--download-info-list token graph-uuid))))
|
||||
|
||||
(rtc-snapshot-graph
|
||||
[this token graph-uuid]
|
||||
(with-write-transit-str
|
||||
(js/Promise. (rtc-core/new-task--snapshot-graph token graph-uuid))))
|
||||
|
||||
(rtc-snapshot-list
|
||||
[this token graph-uuid]
|
||||
(with-write-transit-str
|
||||
(js/Promise. (rtc-core/new-task--snapshot-list token graph-uuid))))
|
||||
|
||||
(rtc-get-graph-keys
|
||||
[this repo]
|
||||
(with-write-transit-str
|
||||
|
||||
52
src/main/frontend/worker/rtc/branch_graph.cljs
Normal file
52
src/main/frontend/worker/rtc/branch_graph.cljs
Normal file
@@ -0,0 +1,52 @@
|
||||
(ns frontend.worker.rtc.branch-graph
|
||||
"Fns to migrate rtc graphs when client-graph-schema and server-graph-schema not matching
|
||||
* when to upload/download to/from remote graph?
|
||||
suppose we have client-schema=X and server-schema=Y.
|
||||
there're several different schema-version graphs on server at the same time.
|
||||
- if X = Y, nothing need to do with migration
|
||||
- if X > Y, client-graph is newer than server-graph, we need to upload this client-graph
|
||||
- if X < Y, client-app need to upgrade, otherwise, this client will keep rtc with server-graph-X
|
||||
- if X < Y, and client-app upgraded, now it should download the server-graph-Y"
|
||||
(:require [clojure.string :as string]))
|
||||
|
||||
(defn major-version
|
||||
"TODO: move to other place later when we decide the final format of schema-version.
|
||||
Compatible with current schema-version number.
|
||||
schema-version-now: 10, a number
|
||||
schema-version-new: \"12.34\", string, <major-num>.<minor-num>"
|
||||
[schema-version]
|
||||
(assert (or (number? schema-version) (string? schema-version)) schema-version)
|
||||
(cond
|
||||
(number? schema-version) schema-version
|
||||
(string? schema-version)
|
||||
(let [[major _minor] (map parse-long (string/split schema-version #"\."))]
|
||||
(assert (some? major) schema-version)
|
||||
major)))
|
||||
|
||||
(defn compare-schemas
|
||||
"Return one of [:create-branch :download nil].
|
||||
when nil, nothing need to do"
|
||||
[server-graph-state server-graph-schema app-schema client-graph-schema]
|
||||
(let [[server-graph-schema app-schema client-graph-schema]
|
||||
(map major-version [server-graph-schema app-schema client-graph-schema])]
|
||||
(cond
|
||||
(= server-graph-schema client-graph-schema)
|
||||
nil
|
||||
|
||||
(> server-graph-schema client-graph-schema)
|
||||
(cond
|
||||
;; client will do some migrations on local-graph,
|
||||
;; so do nothing for now
|
||||
(< server-graph-schema app-schema) nil
|
||||
;; client-app-schema < server-graph-schema,
|
||||
;; so app need to be upgraded, do nothing for now
|
||||
(> server-graph-schema app-schema) nil
|
||||
(= server-graph-schema app-schema) :download)
|
||||
|
||||
(< server-graph-schema client-graph-schema)
|
||||
(cond
|
||||
;; this remote-graph branch is creating now,
|
||||
;; disallow upload a new schema-version graph for now
|
||||
(= "creating" server-graph-state) nil
|
||||
(>= server-graph-schema app-schema) nil
|
||||
(< server-graph-schema app-schema) :create-branch))))
|
||||
@@ -403,19 +403,6 @@
|
||||
[]
|
||||
(m/reduce {} nil (m/eduction (take 1) create-get-state-flow)))
|
||||
|
||||
(defn new-task--snapshot-graph
|
||||
[token graph-uuid]
|
||||
(let [{:keys [get-ws-create-task]} (gen-get-ws-create-map--memoized (ws-util/get-ws-url token))]
|
||||
(m/join #(select-keys % [:snapshot-uuid :graph-uuid])
|
||||
(ws-util/send&recv get-ws-create-task {:action "snapshot-graph"
|
||||
:graph-uuid graph-uuid}))))
|
||||
(defn new-task--snapshot-list
|
||||
[token graph-uuid]
|
||||
(let [{:keys [get-ws-create-task]} (gen-get-ws-create-map--memoized (ws-util/get-ws-url token))]
|
||||
(m/join :snapshot-list
|
||||
(ws-util/send&recv get-ws-create-task {:action "snapshot-list"
|
||||
:graph-uuid graph-uuid}))))
|
||||
|
||||
(defn new-task--upload-graph
|
||||
[token repo remote-graph-name]
|
||||
(m/sp
|
||||
|
||||
@@ -176,6 +176,7 @@
|
||||
api-schema)))
|
||||
api-schema-seq)))))
|
||||
|
||||
;;; TODO: :graph-uuid's schema :uuid instead of :string
|
||||
(def ^:large-vars/data-var data-to-ws-schema
|
||||
(mu/closed-schema
|
||||
(with-shared-schema-attrs
|
||||
@@ -184,7 +185,8 @@
|
||||
[:map]]
|
||||
["register-graph-updates"
|
||||
[:map
|
||||
[:graph-uuid :string]]]
|
||||
[:graph-uuid :string]
|
||||
[:schema-version :string]]]
|
||||
["apply-ops"
|
||||
[:or
|
||||
[:map
|
||||
@@ -192,6 +194,7 @@
|
||||
[:action :string]
|
||||
[:profile {:optional true} :boolean]
|
||||
[:graph-uuid :string]
|
||||
[:schema-version :string]
|
||||
[:ops [:sequential to-ws-op-schema]]
|
||||
[:t-before :int]]
|
||||
[:map
|
||||
@@ -204,19 +207,16 @@
|
||||
["upload-graph"
|
||||
[:map
|
||||
[:s3-key :string]
|
||||
[:graph-name :string]]]
|
||||
[:graph-name :string]
|
||||
[:schema-version :string]]]
|
||||
["download-graph"
|
||||
[:map
|
||||
[:graph-uuid :string]]]
|
||||
[:graph-uuid :string]
|
||||
[:schema-version :string]]]
|
||||
["download-info-list"
|
||||
[:map
|
||||
[:graph-uuid :string]]]
|
||||
["snapshot-list"
|
||||
[:map
|
||||
[:graph-uuid :string]]]
|
||||
["snapshot-graph"
|
||||
[:map
|
||||
[:graph-uuid :string]]]
|
||||
[:graph-uuid :string]
|
||||
[:schema-version :string]]]
|
||||
["grant-access"
|
||||
[:map
|
||||
[:graph-uuid :uuid]
|
||||
@@ -227,10 +227,12 @@
|
||||
[:graph-uuid :uuid]]]
|
||||
["inject-users-info"
|
||||
[:map
|
||||
[:graph-uuid :uuid]]]
|
||||
[:graph-uuid :uuid]
|
||||
[:schema-version :string]]]
|
||||
["delete-graph"
|
||||
[:map
|
||||
[:graph-uuid :uuid]]]
|
||||
[:graph-uuid :uuid]
|
||||
[:schema-version :string]]]
|
||||
["query-block-content-versions"
|
||||
[:map
|
||||
[:graph-uuid :string]
|
||||
@@ -246,7 +248,8 @@
|
||||
[::m/default extra-attr-map-schema]]]]]]
|
||||
["get-graph-skeleton"
|
||||
[:map
|
||||
[:graph-uuid :string]]]
|
||||
[:graph-uuid :string]
|
||||
[:schema-version :string]]]
|
||||
["get-assets-upload-urls"
|
||||
[:map
|
||||
[:graph-uuid :string]
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
(ns frontend.worker.rtc.migrate
|
||||
"Fns to migrate rtc graphs when client-graph-schema and server-graph-schema not matching
|
||||
* when to upload/download to/from remote graph?
|
||||
suppose we have client-schema=X and server-schema=Y.
|
||||
there're several different schema-version graphs on server at the same time.
|
||||
- if X = Y, nothing need to do with migration
|
||||
- if X > Y, client-graph is newer than server-graph, we need to upload this client-graph
|
||||
- if X < Y, client-app need to upgrade, otherwise, this client will keep rtc with server-graph-X
|
||||
- if X < Y, and client-app upgraded, now it should download the server-graph-Y"
|
||||
(:require [logseq.db.frontend.schema :as db-schema]))
|
||||
|
||||
(def client-app-schema db-schema/version)
|
||||
|
||||
(defn compare-schemas
|
||||
"Return one of [:upload :download nil].
|
||||
when nil, nothing need to do"
|
||||
[server-graph-state server-graph-schema app-schema client-graph-schema]
|
||||
(cond
|
||||
(= server-graph-schema client-graph-schema)
|
||||
nil
|
||||
|
||||
(> server-graph-schema client-graph-schema)
|
||||
(cond
|
||||
;; client will do some migrations on local-graph,
|
||||
;; so rtc-migrate do nothing for now
|
||||
(< server-graph-schema app-schema) nil
|
||||
;; server-graph is newer than client-graph,
|
||||
;; but client-app-schema > server-graph-schema,
|
||||
;; so, app need to be upgraded, do nothing for now
|
||||
(> server-graph-schema app-schema) nil
|
||||
(= server-graph-schema app-schema) :download)
|
||||
|
||||
(< server-graph-schema client-graph-schema)
|
||||
(cond
|
||||
;; TODO: this remote-graph is migrating now,
|
||||
;; disallow upload a new schema-version graph for now
|
||||
(= :TODO-migrating server-graph-state) nil
|
||||
:else :upload
|
||||
)))
|
||||
@@ -4,12 +4,9 @@
|
||||
[datascript.core :as d]
|
||||
[frontend.worker.rtc.ws-util :as ws-util]
|
||||
[frontend.worker.util :as worker-util]
|
||||
[logseq.db :as ldb]
|
||||
[missionary.core :as m]))
|
||||
|
||||
(defn- get-schema-version
|
||||
[db]
|
||||
(:kv/value (d/entity db :logseq.kv/schema-version)))
|
||||
|
||||
(defn- get-builtin-db-idents
|
||||
[db]
|
||||
(d/q '[:find [?i ...]
|
||||
@@ -35,7 +32,7 @@
|
||||
(throw (ex-info "Unavailable2" {:remote-ex remote-ex}))))
|
||||
(let [{:keys [server-schema-version server-builtin-db-idents]} r
|
||||
client-builtin-db-idents (set (get-builtin-db-idents db))
|
||||
client-schema-version (get-schema-version db)]
|
||||
client-schema-version (ldb/get-graph-schema-version db)]
|
||||
(when (not= client-schema-version server-schema-version)
|
||||
(worker-util/post-message :notification
|
||||
[[:div
|
||||
|
||||
Reference in New Issue
Block a user