diff --git a/src/main/frontend/worker/db_core.cljs b/src/main/frontend/worker/db_core.cljs index 378b2c205c..3fed17c119 100644 --- a/src/main/frontend/worker/db_core.cljs +++ b/src/main/frontend/worker/db_core.cljs @@ -11,11 +11,11 @@ [frontend.common.graph-view :as graph-view] [frontend.common.missionary :as c.m] [frontend.common.thread-api :as thread-api :refer [def-thread-api]] + [frontend.worker.graph-dir :as graph-dir] [frontend.worker.platform :as platform] [frontend.worker-common.util :as worker-util] [frontend.worker.db-listener :as db-listener] [frontend.worker.db-metadata :as worker-db-metadata] - [frontend.worker.db-worker-node-lock :as db-lock] [frontend.worker.db.fix :as db-fix] [frontend.worker.db.migrate :as db-migrate] [frontend.worker.db.validate :as worker-db-validate] @@ -73,7 +73,7 @@ (defn- storage-pool-name [graph] (if (node-runtime?) - (db-lock/repo->graph-dir-key graph) + (graph-dir/repo->graph-dir-key graph) (worker-util/get-pool-name graph))) (defn- get-storage-pool diff --git a/src/main/frontend/worker/db_worker_node_lock.cljs b/src/main/frontend/worker/db_worker_node_lock.cljs index e63ec8b3d6..77044572bf 100644 --- a/src/main/frontend/worker/db_worker_node_lock.cljs +++ b/src/main/frontend/worker/db_worker_node_lock.cljs @@ -4,6 +4,7 @@ ["os" :as os] ["path" :as node-path] [clojure.string :as string] + [frontend.worker.graph-dir :as graph-dir] [frontend.worker-common.util :as worker-util] [lambdaisland.glogi :as log] [logseq.common.config :as common-config] @@ -21,10 +22,7 @@ (defn repo->graph-dir-key [repo] - (when (seq repo) - (if (string/starts-with? repo common-config/db-version-prefix) - (subs repo (count common-config/db-version-prefix)) - repo))) + (graph-dir/repo->graph-dir-key repo)) (defn canonical-graph-dir-key? [graph-dir-key] diff --git a/src/main/frontend/worker/graph_dir.cljs b/src/main/frontend/worker/graph_dir.cljs new file mode 100644 index 0000000000..d23a22b56f --- /dev/null +++ b/src/main/frontend/worker/graph_dir.cljs @@ -0,0 +1,11 @@ +(ns frontend.worker.graph-dir + "Platform-agnostic graph directory naming helpers." + (:require [clojure.string :as string] + [logseq.common.config :as common-config])) + +(defn repo->graph-dir-key + [repo] + (when (seq repo) + (if (string/starts-with? repo common-config/db-version-prefix) + (subs repo (count common-config/db-version-prefix)) + repo))) diff --git a/src/test/frontend/worker/graph_dir_test.cljs b/src/test/frontend/worker/graph_dir_test.cljs new file mode 100644 index 0000000000..f9a62241c2 --- /dev/null +++ b/src/test/frontend/worker/graph_dir_test.cljs @@ -0,0 +1,11 @@ +(ns frontend.worker.graph-dir-test + (:require [cljs.test :refer [deftest is testing]] + [frontend.worker.graph-dir :as graph-dir])) + +(deftest repo->graph-dir-key-strips-db-prefix + (testing "db-prefixed repo is mapped to prefix-free graph dir key" + (is (= "demo" (graph-dir/repo->graph-dir-key "logseq_db_demo"))))) + +(deftest repo->graph-dir-key-keeps-prefix-free-name + (testing "prefix-free repo remains unchanged" + (is (= "demo" (graph-dir/repo->graph-dir-key "demo")))))