fix: open db graph urls

Also introduced var for logseq_db_ in deps
feat/datascript-storage-test
Gabriel Horner 2023-11-27 10:55:22 -05:00
parent c468d05845
commit 5e547a1663
6 changed files with 27 additions and 20 deletions

View File

@ -3,7 +3,8 @@
(:require ["path" :as node-path] (:require ["path" :as node-path]
["better-sqlite3" :as sqlite3] ["better-sqlite3" :as sqlite3]
[clojure.string :as string] [clojure.string :as string]
[cljs-bean.core :as bean])) [cljs-bean.core :as bean]
[logseq.db.sqlite.util :as sqlite-util]))
;; use built-in blocks to represent db schema, config, custom css, custom js, etc. ;; use built-in blocks to represent db schema, config, custom css, custom js, etc.
@ -22,7 +23,7 @@
(defn sanitize-db-name (defn sanitize-db-name
[db-name] [db-name]
(-> db-name (-> db-name
(string/replace "logseq_db_" "") (string/replace sqlite-util/db-version-prefix "")
(string/replace "/" "_") (string/replace "/" "_")
(string/replace "\\" "_") (string/replace "\\" "_")
(string/replace ":" "_"))) ;; windows (string/replace ":" "_"))) ;; windows

View File

@ -31,6 +31,8 @@
(contains? (set (:block/type block)) "macro") 7 (contains? (set (:block/type block)) "macro") 7
:else 5)) :else 5))
(defonce db-version-prefix "logseq_db_")
(defn time-ms (defn time-ms
"Copy of util/time-ms. Too basic to couple this to main app" "Copy of util/time-ms. Too basic to couple this to main app"
[] []

View File

@ -5,7 +5,8 @@ necessary db filtering"
[goog.string :as gstring] [goog.string :as gstring]
[goog.string.format] [goog.string.format]
[datascript.transit :as dt] [datascript.transit :as dt]
[logseq.publishing.db :as db])) [logseq.publishing.db :as db]
[logseq.db.sqlite.util :as sqlite-util]))
;; Copied from hiccup but tweaked for publish usage ;; Copied from hiccup but tweaked for publish usage
;; Any changes here should also be made in frontend.publishing/unescape-html ;; Any changes here should also be made in frontend.publishing/unescape-html
@ -142,7 +143,7 @@ generated index.html string and assets used by the html"
asset-filenames (remove nil? asset-filenames') asset-filenames (remove nil? asset-filenames')
db-str (dt/write-transit-str db) db-str (dt/write-transit-str db)
repo-name (if db-graph? "logseq_db_local" "local") repo-name (if db-graph? (str sqlite-util/db-version-prefix "local") "local")
;; The repo-name is used by the client and thus determines whether ;; The repo-name is used by the client and thus determines whether
;; it's a db graph or not ;; it's a db graph or not
state (assoc app-state state (assoc app-state

View File

@ -245,7 +245,7 @@
(->> (common-graph/read-directories dir) (->> (common-graph/read-directories dir)
(remove (fn [s] (= s db/unlinked-graphs-dir))) (remove (fn [s] (= s db/unlinked-graphs-dir)))
(map graph-name->path) (map graph-name->path)
(map (fn [s] (str "logseq_db_" s)))))) (map (fn [s] (str sqlite-util/db-version-prefix s))))))
(defn- get-graphs (defn- get-graphs
[] []
@ -255,13 +255,15 @@
;; TODO support alias mechanism ;; TODO support alias mechanism
(defn get-graph-name (defn get-graph-name
"Given a graph's name of string, returns the graph's fullname. "Given a graph's name of string, returns the graph's fullname. For example, given
E.g., given `cat`, returns `logseq_local_<path_to_directory>/cat` `cat`, returns `logseq_local_<path_to_directory>/cat` for a file graph and
Returns `nil` if no such graph exists." `logseq_db_cat` for a db graph. Returns `nil` if no such graph exists."
[graph-identifier] [graph-identifier]
(->> (get-graphs) (->> (get-graphs)
(some #(when (string/ends-with? (utils/normalize-lc %) (some #(when (or
(str "/" (utils/normalize-lc graph-identifier))) (= (utils/normalize-lc %) (utils/normalize-lc (str sqlite-util/db-version-prefix graph-identifier)))
(string/ends-with? (utils/normalize-lc %)
(str "/" (utils/normalize-lc graph-identifier))))
%)))) %))))
(defmethod handle :getGraphs [_window [_]] (defmethod handle :getGraphs [_window [_]]

View File

@ -229,9 +229,7 @@
(let [remote? (:remote? (first (filter #(= current-repo (:url %)) repos))) (let [remote? (:remote? (first (filter #(= current-repo (:url %)) repos)))
repo-name (db/get-repo-name current-repo) repo-name (db/get-repo-name current-repo)
short-repo-name (if repo-name short-repo-name (if repo-name
(if (config/db-based-graph? repo-name) (db/get-short-repo-name repo-name)
(string/replace-first repo-name config/db-version-prefix "")
(db/get-short-repo-name repo-name))
"Select a Graph")] "Select a Graph")]
[:a.item.group.flex.items-center.p-2.text-sm.font-medium.rounded-md [:a.item.group.flex.items-center.p-2.text-sm.font-medium.rounded-md

View File

@ -36,15 +36,18 @@
(defn get-short-repo-name (defn get-short-repo-name
"repo-name: from get-repo-name. Dir/Name => Name" "repo-name: from get-repo-name. Dir/Name => Name"
[repo-name] [repo-name]
(cond (let [repo-name' (cond
(util/electron?) (util/electron?)
(text/get-file-basename repo-name) (text/get-file-basename repo-name)
(mobile-util/native-platform?) (mobile-util/native-platform?)
(gp-util/safe-decode-uri-component (text/get-file-basename repo-name)) (gp-util/safe-decode-uri-component (text/get-file-basename repo-name))
:else :else
repo-name)) repo-name)]
(if (config/db-based-graph? repo-name')
(string/replace-first repo-name' config/db-version-prefix "")
repo-name')))
(defn datascript-db (defn datascript-db
[repo] [repo]