refactor(worker): extract graph dir key helper

This commit is contained in:
rcmerci
2026-02-07 09:33:02 +08:00
parent a1ff32f6dd
commit a8b118a721
4 changed files with 26 additions and 6 deletions

View File

@@ -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

View File

@@ -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]

View File

@@ -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)))

View File

@@ -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")))))