add :logseq.kv/local-graph-uuid

This commit is contained in:
Tienson Qin
2026-01-01 14:11:39 +08:00
parent 3078f2a900
commit b55550ed3e
6 changed files with 24 additions and 18 deletions

View File

@@ -587,12 +587,14 @@
(def kv sqlite-util/kv)
;; TODO: why not generate a UUID for all local graphs?
;; And prefer this local graph UUID when picking an ID for new rtc graph?
(defn get-graph-rtc-uuid
[db]
(when db (get-key-value db :logseq.kv/graph-uuid)))
(defn get-graph-local-uuid
[db]
(when db (get-key-value db :logseq.kv/local-graph-uuid)))
(defn get-graph-schema-version
[db]
(when db (get-key-value db :logseq.kv/schema-version)))

View File

@@ -10,6 +10,9 @@
:logseq.kv/graph-uuid {:doc "Store graph-uuid if it's a rtc enabled graph"
:rtc {:rtc/ignore-entity-when-init-upload true
:rtc/ignore-entity-when-init-download true}}
:logseq.kv/local-graph-uuid {:doc "Store graph-uuid if it's a local graph"
:rtc {:rtc/ignore-entity-when-init-upload true
:rtc/ignore-entity-when-init-download true}}
:logseq.kv/import-type {:doc "If graph is imported, identifies how a graph is imported including which UI or CLI import process. CLI scripts can set this to a custom value.
UI values include :file-graph and :sqlite-db and CLI values start with :cli e.g. :cli/default."}
:logseq.kv/imported-at {:doc "Time if graph is imported"}

View File

@@ -237,7 +237,8 @@
graph-git-sha
(conj (sqlite-util/kv :logseq.kv/graph-git-sha graph-git-sha))
true
(conj (sqlite-util/kv :logseq.kv/graph-uuid (common-uuid/gen-uuid))))
(conj (sqlite-util/kv :logseq.kv/local-graph-uuid
(uuid (str "loc" (subs (str (common-uuid/gen-uuid)) 3))))))
initial-files (build-initial-files config-content)
{properties-tx :tx :keys [properties]} (build-initial-properties)
db-ident->properties (zipmap (map :db/ident properties) properties)

View File

@@ -364,25 +364,25 @@
(let [repo (state/get-current-repo)]
(when-let [db* (and repo (db/get-db repo))]
(if (and page (:db/id page))
(p/let [graph-uuid (some-> (ldb/get-graph-rtc-uuid db*) str)
(p/let [graph-id (some->
(or (ldb/get-graph-rtc-uuid db*)
(ldb/get-graph-local-uuid db*))
str)
payload (state/<invoke-db-worker :thread-api/build-publish-page-payload
repo
(:db/id page)
graph-uuid)]
(:db/id page))]
(if payload
(-> (p/let [_ (<upload-assets! repo graph-uuid payload)
custom-assets (<upload-custom-publish-assets! repo graph-uuid)]
(-> (p/let [_ (<upload-assets! repo graph-id payload)
custom-assets (<upload-custom-publish-assets! repo graph-id)]
(<post-publish! payload {:password password
:custom-assets custom-assets}))
(p/then (fn [resp]
(p/let [json (.json resp)
data (bean/->clj json)]
(let [short-url (:short_url data)
graph-uuid (or (:graph-uuid payload)
(some-> (ldb/get-graph-rtc-uuid db*) str))
page-uuid (str (:block/uuid page))
fallback-url (when (and graph-uuid page-uuid)
(str config/PUBLISH-API-BASE "/page/" graph-uuid "/" page-uuid))
page-id (str (:block/uuid page))
fallback-url (when (and graph-id page-id)
(str config/PUBLISH-API-BASE "/page/" graph-id "/" page-id))
url (or (when short-url
(str config/PUBLISH-API-BASE short-url))
fallback-url)]

View File

@@ -194,9 +194,10 @@
datoms))
(defn- build-publish-page-payload
[db entity graph-uuid]
[db entity]
(let [{:keys [blocks eids]} (publish-collect-page-eids db entity)
graph-uuid (or graph-uuid (ldb/get-graph-rtc-uuid db))
graph-uuid (or (ldb/get-graph-rtc-uuid db)
(ldb/get-graph-local-uuid db))
refs (when graph-uuid
(publish-refs-from-blocks db blocks entity graph-uuid))
tags (page-tags entity)
@@ -223,9 +224,9 @@
:datoms datoms}))
(def-thread-api :thread-api/build-publish-page-payload
[repo eid graph-uuid]
[repo eid]
(when-let [conn (worker-state/get-datascript-conn repo)]
(let [db @conn
page-entity (d/entity db eid)]
(when (and page-entity (:db/id page-entity))
(build-publish-page-payload db page-entity graph-uuid)))))
(build-publish-page-payload db page-entity)))))

View File

@@ -191,7 +191,6 @@
:graph-name remote-graph-name
:encrypted-aes-key
(ldb/write-transit-str encrypted-aes-key)}))]
;; FIXME: use local graph uuid instead of creating new one
(if-let [graph-uuid (:graph-uuid upload-resp)]
(let [schema-version (ldb/get-graph-schema-version @conn)]
(ldb/transact! conn