Skip to content

Commit b55550e

Browse files
committed
add :logseq.kv/local-graph-uuid
1 parent 3078f2a commit b55550e

6 files changed

Lines changed: 24 additions & 18 deletions

File tree

deps/db/src/logseq/db.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,14 @@
587587

588588
(def kv sqlite-util/kv)
589589

590-
;; TODO: why not generate a UUID for all local graphs?
591-
;; And prefer this local graph UUID when picking an ID for new rtc graph?
592590
(defn get-graph-rtc-uuid
593591
[db]
594592
(when db (get-key-value db :logseq.kv/graph-uuid)))
595593

594+
(defn get-graph-local-uuid
595+
[db]
596+
(when db (get-key-value db :logseq.kv/local-graph-uuid)))
597+
596598
(defn get-graph-schema-version
597599
[db]
598600
(when db (get-key-value db :logseq.kv/schema-version)))

deps/db/src/logseq/db/frontend/kv_entity.cljs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
:logseq.kv/graph-uuid {:doc "Store graph-uuid if it's a rtc enabled graph"
1111
:rtc {:rtc/ignore-entity-when-init-upload true
1212
:rtc/ignore-entity-when-init-download true}}
13+
:logseq.kv/local-graph-uuid {:doc "Store graph-uuid if it's a local graph"
14+
:rtc {:rtc/ignore-entity-when-init-upload true
15+
:rtc/ignore-entity-when-init-download true}}
1316
: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.
1417
UI values include :file-graph and :sqlite-db and CLI values start with :cli e.g. :cli/default."}
1518
:logseq.kv/imported-at {:doc "Time if graph is imported"}

deps/db/src/logseq/db/sqlite/create_graph.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@
237237
graph-git-sha
238238
(conj (sqlite-util/kv :logseq.kv/graph-git-sha graph-git-sha))
239239
true
240-
(conj (sqlite-util/kv :logseq.kv/graph-uuid (common-uuid/gen-uuid))))
240+
(conj (sqlite-util/kv :logseq.kv/local-graph-uuid
241+
(uuid (str "loc" (subs (str (common-uuid/gen-uuid)) 3))))))
241242
initial-files (build-initial-files config-content)
242243
{properties-tx :tx :keys [properties]} (build-initial-properties)
243244
db-ident->properties (zipmap (map :db/ident properties) properties)

src/main/frontend/handler/publish.cljs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,25 +364,25 @@
364364
(let [repo (state/get-current-repo)]
365365
(when-let [db* (and repo (db/get-db repo))]
366366
(if (and page (:db/id page))
367-
(p/let [graph-uuid (some-> (ldb/get-graph-rtc-uuid db*) str)
367+
(p/let [graph-id (some->
368+
(or (ldb/get-graph-rtc-uuid db*)
369+
(ldb/get-graph-local-uuid db*))
370+
str)
368371
payload (state/<invoke-db-worker :thread-api/build-publish-page-payload
369372
repo
370-
(:db/id page)
371-
graph-uuid)]
373+
(:db/id page))]
372374
(if payload
373-
(-> (p/let [_ (<upload-assets! repo graph-uuid payload)
374-
custom-assets (<upload-custom-publish-assets! repo graph-uuid)]
375+
(-> (p/let [_ (<upload-assets! repo graph-id payload)
376+
custom-assets (<upload-custom-publish-assets! repo graph-id)]
375377
(<post-publish! payload {:password password
376378
:custom-assets custom-assets}))
377379
(p/then (fn [resp]
378380
(p/let [json (.json resp)
379381
data (bean/->clj json)]
380382
(let [short-url (:short_url data)
381-
graph-uuid (or (:graph-uuid payload)
382-
(some-> (ldb/get-graph-rtc-uuid db*) str))
383-
page-uuid (str (:block/uuid page))
384-
fallback-url (when (and graph-uuid page-uuid)
385-
(str config/PUBLISH-API-BASE "/page/" graph-uuid "/" page-uuid))
383+
page-id (str (:block/uuid page))
384+
fallback-url (when (and graph-id page-id)
385+
(str config/PUBLISH-API-BASE "/page/" graph-id "/" page-id))
386386
url (or (when short-url
387387
(str config/PUBLISH-API-BASE short-url))
388388
fallback-url)]

src/main/frontend/worker/publish.cljs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@
194194
datoms))
195195

196196
(defn- build-publish-page-payload
197-
[db entity graph-uuid]
197+
[db entity]
198198
(let [{:keys [blocks eids]} (publish-collect-page-eids db entity)
199-
graph-uuid (or graph-uuid (ldb/get-graph-rtc-uuid db))
199+
graph-uuid (or (ldb/get-graph-rtc-uuid db)
200+
(ldb/get-graph-local-uuid db))
200201
refs (when graph-uuid
201202
(publish-refs-from-blocks db blocks entity graph-uuid))
202203
tags (page-tags entity)
@@ -223,9 +224,9 @@
223224
:datoms datoms}))
224225

225226
(def-thread-api :thread-api/build-publish-page-payload
226-
[repo eid graph-uuid]
227+
[repo eid]
227228
(when-let [conn (worker-state/get-datascript-conn repo)]
228229
(let [db @conn
229230
page-entity (d/entity db eid)]
230231
(when (and page-entity (:db/id page-entity))
231-
(build-publish-page-payload db page-entity graph-uuid)))))
232+
(build-publish-page-payload db page-entity)))))

src/main/frontend/worker/rtc/full_upload_download_graph.cljs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
:graph-name remote-graph-name
192192
:encrypted-aes-key
193193
(ldb/write-transit-str encrypted-aes-key)}))]
194-
;; FIXME: use local graph uuid instead of creating new one
195194
(if-let [graph-uuid (:graph-uuid upload-resp)]
196195
(let [schema-version (ldb/get-graph-schema-version @conn)]
197196
(ldb/transact! conn

0 commit comments

Comments
 (0)