mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 15:09:41 +00:00
chore: mv file graph specific fns out ldb
This commit is contained in:
37
src/main/frontend/common/file_based/db.cljs
Normal file
37
src/main/frontend/common/file_based/db.cljs
Normal file
@@ -0,0 +1,37 @@
|
||||
(ns frontend.common.file-based.db
|
||||
"Database fns for file graphs that are used by worker and frontend"
|
||||
(:require [clojure.string :as string]
|
||||
[datascript.core :as d]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.db.file-based.rules :as file-rules]))
|
||||
|
||||
(defn get-namespace-pages
|
||||
"Accepts both sanitized and unsanitized namespaces"
|
||||
[db namespace']
|
||||
(assert (string? namespace'))
|
||||
(let [namespace'' (common-util/page-name-sanity-lc namespace')
|
||||
pull-attrs [:db/id :block/name :block/original-name :block/namespace
|
||||
{:block/file [:db/id :file/path]}]]
|
||||
(d/q
|
||||
[:find [(list 'pull '?c pull-attrs) '...]
|
||||
:in '$ '% '?namespace
|
||||
:where
|
||||
['?p :block/name '?namespace]
|
||||
(list 'namespace '?p '?c)]
|
||||
db
|
||||
(:namespace file-rules/rules)
|
||||
namespace'')))
|
||||
|
||||
(defn get-pages-by-name-partition
|
||||
[db partition']
|
||||
(when-not (string/blank? partition')
|
||||
(let [partition'' (common-util/page-name-sanity-lc (string/trim partition'))
|
||||
ids (->> (d/datoms db :aevt :block/name)
|
||||
(filter (fn [datom]
|
||||
(let [page (:v datom)]
|
||||
(string/includes? page partition''))))
|
||||
(map :e))]
|
||||
(when (seq ids)
|
||||
(d/pull-many db
|
||||
'[:db/id :block/name :block/title]
|
||||
ids)))))
|
||||
@@ -6,6 +6,7 @@
|
||||
[clojure.string :as string]
|
||||
[clojure.walk :as walk]
|
||||
[datascript.core :as d]
|
||||
[frontend.common.file-based.db :as common-file-db]
|
||||
[frontend.config :as config]
|
||||
[frontend.date :as date]
|
||||
[frontend.db.conn :as conn]
|
||||
@@ -912,7 +913,7 @@ independent of format as format specific heading characters are stripped"
|
||||
(defn get-namespace-pages
|
||||
"Accepts both sanitized and unsanitized namespaces"
|
||||
[repo namespace]
|
||||
(ldb/get-namespace-pages (conn/get-db repo) namespace {:db-graph? (config/db-based-graph? repo)}))
|
||||
(common-file-db/get-namespace-pages (conn/get-db repo) namespace))
|
||||
|
||||
(defn- tree [flat-col root]
|
||||
(let [sort-fn #(sort-by :block/name %)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns frontend.worker.handler.page.file-based.rename
|
||||
"File based page rename"
|
||||
(:require [frontend.worker.handler.page :as worker-page]
|
||||
(:require [frontend.common.file-based.db :as common-file-db]
|
||||
[frontend.worker.handler.page :as worker-page]
|
||||
[datascript.core :as d]
|
||||
[clojure.string :as string]
|
||||
[clojure.walk :as walk]
|
||||
@@ -254,7 +255,7 @@
|
||||
(defn- rename-namespace-pages!
|
||||
"Original names (unsanitized only)"
|
||||
[repo conn config old-name new-name]
|
||||
(let [pages (ldb/get-namespace-pages @conn old-name {})
|
||||
(let [pages (common-file-db/get-namespace-pages @conn old-name)
|
||||
page (d/pull @conn '[*] [:block/name (common-util/page-name-sanity-lc old-name)])
|
||||
pages (cons page pages)]
|
||||
(doseq [{:block/keys [name title]} pages]
|
||||
@@ -274,8 +275,8 @@
|
||||
(let [nested-page-str (page-ref/->page-ref (common-util/page-name-sanity-lc old-ns-name))
|
||||
ns-prefix-format-str (str page-ref/left-brackets "%s/")
|
||||
ns-prefix (common-util/format ns-prefix-format-str (common-util/page-name-sanity-lc old-ns-name))
|
||||
nested-pages (ldb/get-pages-by-name-partition @conn nested-page-str)
|
||||
nested-pages-ns (ldb/get-pages-by-name-partition @conn ns-prefix)]
|
||||
nested-pages (common-file-db/get-pages-by-name-partition @conn nested-page-str)
|
||||
nested-pages-ns (common-file-db/get-pages-by-name-partition @conn ns-prefix)]
|
||||
(when nested-pages
|
||||
;; rename page "[[obsidian]] is a tool" to "[[logseq]] is a tool"
|
||||
(doseq [{:block/keys [name title]} nested-pages]
|
||||
|
||||
Reference in New Issue
Block a user