mirror of https://github.com/logseq/logseq
fix: file graph issues
parent
349542b7b9
commit
bcd04dba05
|
@ -6,7 +6,8 @@
|
||||||
[logseq.db.sqlite.util :as sqlite-util]
|
[logseq.db.sqlite.util :as sqlite-util]
|
||||||
[logseq.common.util.date-time :as date-time-util]
|
[logseq.common.util.date-time :as date-time-util]
|
||||||
[logseq.common.util :as common-util]
|
[logseq.common.util :as common-util]
|
||||||
[logseq.common.config :as common-config]))
|
[logseq.common.config :as common-config]
|
||||||
|
[logseq.db.frontend.entity-plus :as entity-plus]))
|
||||||
|
|
||||||
(defn- get-pages-by-name
|
(defn- get-pages-by-name
|
||||||
[db page-name]
|
[db page-name]
|
||||||
|
@ -88,6 +89,7 @@
|
||||||
|
|
||||||
(defn- property-with-values
|
(defn- property-with-values
|
||||||
[db block]
|
[db block]
|
||||||
|
(when (entity-plus/db-based-graph? db)
|
||||||
(let [block (d/entity db (:db/id block))
|
(let [block (d/entity db (:db/id block))
|
||||||
class-properties (when (contains? (:block/type block) "class")
|
class-properties (when (contains? (:block/type block) "class")
|
||||||
(let [property-ids (map :db/id (:class/schema.properties block))]
|
(let [property-ids (map :db/id (:class/schema.properties block))]
|
||||||
|
@ -131,7 +133,7 @@
|
||||||
value-blocks
|
value-blocks
|
||||||
[pair]))))
|
[pair]))))
|
||||||
pairs)))]
|
pairs)))]
|
||||||
(concat class-properties block-properties)))
|
(concat class-properties block-properties))))
|
||||||
|
|
||||||
(defn get-block-and-children
|
(defn get-block-and-children
|
||||||
[db id children?]
|
[db id children?]
|
||||||
|
@ -261,7 +263,8 @@
|
||||||
latest-journals (get-latest-journals db 3)
|
latest-journals (get-latest-journals db 3)
|
||||||
all-files (get-all-files db)
|
all-files (get-all-files db)
|
||||||
home-page-data (get-home-page db all-files)
|
home-page-data (get-home-page db all-files)
|
||||||
structured-blocks (get-structured-blocks db)
|
structured-blocks (when (entity-plus/db-based-graph? db)
|
||||||
|
(get-structured-blocks db))
|
||||||
data (concat idents structured-blocks favorites latest-journals all-files home-page-data)]
|
data (concat idents structured-blocks favorites latest-journals all-files home-page-data)]
|
||||||
{:schema schema
|
{:schema schema
|
||||||
:initial-data data}))
|
:initial-data data}))
|
||||||
|
|
|
@ -248,10 +248,9 @@
|
||||||
:on-enter non-exist-block-handler
|
:on-enter non-exist-block-handler
|
||||||
:empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (t :editor/block-search)]
|
:empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (t :editor/block-search)]
|
||||||
:item-render (fn [{:block/keys [page uuid]}] ;; content returned from search engine is normalized
|
:item-render (fn [{:block/keys [page uuid]}] ;; content returned from search engine is normalized
|
||||||
(let [page (or (:block/original-name page)
|
(let [page-entity (db/entity [:block/uuid page])
|
||||||
(:block/name page))
|
|
||||||
repo (state/sub :git/current-repo)
|
repo (state/sub :git/current-repo)
|
||||||
format (db/get-page-format page)
|
format (get page-entity :block/format :markdown)
|
||||||
block (db-model/query-block-by-uuid uuid)
|
block (db-model/query-block-by-uuid uuid)
|
||||||
content (:block/content block)]
|
content (:block/content block)]
|
||||||
(when-not (string/blank? content)
|
(when-not (string/blank? content)
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
(p/let [result (.search-blocks sqlite (state/get-current-repo) q (bean/->js option))
|
(p/let [result (.search-blocks sqlite (state/get-current-repo) q (bean/->js option))
|
||||||
result (bean/->clj result)]
|
result (bean/->clj result)]
|
||||||
(keep (fn [{:keys [content page] :as block}]
|
(keep (fn [{:keys [content page] :as block}]
|
||||||
{:block/uuid (uuid (:uuid block))
|
{:page? (= (:uuid block) page)
|
||||||
|
:block/uuid (uuid (:uuid block))
|
||||||
:block/content content
|
:block/content content
|
||||||
:block/page (uuid page)}) result))
|
:block/page (uuid page)}) result))
|
||||||
(p/resolved nil)))
|
(p/resolved nil)))
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
[frontend.worker.util :as worker-util]
|
[frontend.worker.util :as worker-util]
|
||||||
[logseq.db.sqlite.util :as sqlite-util]
|
[logseq.db.sqlite.util :as sqlite-util]
|
||||||
[logseq.common.util :as common-util]
|
[logseq.common.util :as common-util]
|
||||||
[logseq.db :as ldb]))
|
[logseq.db :as ldb]
|
||||||
|
[cljs-bean.core :as bean]))
|
||||||
|
|
||||||
;; TODO: use sqlite for fuzzy search
|
;; TODO: use sqlite for fuzzy search
|
||||||
(defonce indices (atom nil))
|
(defonce indices (atom nil))
|
||||||
|
@ -81,10 +82,14 @@
|
||||||
[^Object db blocks]
|
[^Object db blocks]
|
||||||
(.transaction db (fn [tx]
|
(.transaction db (fn [tx]
|
||||||
(doseq [item blocks]
|
(doseq [item blocks]
|
||||||
|
(if (and (common-util/uuid-string? (.-id item))
|
||||||
|
(common-util/uuid-string? (.-page item)))
|
||||||
(.exec tx #js {:sql "INSERT INTO blocks (id, content, page) VALUES ($id, $content, $page) ON CONFLICT (id) DO UPDATE SET (content, page) = ($content, $page)"
|
(.exec tx #js {:sql "INSERT INTO blocks (id, content, page) VALUES ($id, $content, $page) ON CONFLICT (id) DO UPDATE SET (content, page) = ($content, $page)"
|
||||||
:bind #js {:$id (.-id item)
|
:bind #js {:$id (.-id item)
|
||||||
:$content (.-content item)
|
:$content (.-content item)
|
||||||
:$page (.-page item)}})))))
|
:$page (.-page item)}})
|
||||||
|
(throw (ex-info "Search upsert-blocks wrong data: "
|
||||||
|
(bean/->clj item))))))))
|
||||||
|
|
||||||
(defn delete-blocks!
|
(defn delete-blocks!
|
||||||
[db ids]
|
[db ids]
|
||||||
|
@ -158,10 +163,11 @@
|
||||||
matched-result (search-blocks-aux db match-sql match-input page limit)
|
matched-result (search-blocks-aux db match-sql match-input page limit)
|
||||||
non-match-result (search-blocks-aux db non-match-sql non-match-input page limit)
|
non-match-result (search-blocks-aux db non-match-sql non-match-input page limit)
|
||||||
all-result (->> (concat matched-result non-match-result)
|
all-result (->> (concat matched-result non-match-result)
|
||||||
(map (fn [[id page _content snippet]]
|
(map (fn [result]
|
||||||
|
(let [[id page _content snippet] result]
|
||||||
{:uuid id
|
{:uuid id
|
||||||
:content snippet
|
:content snippet
|
||||||
:page page})))]
|
:page page}))))]
|
||||||
(->>
|
(->>
|
||||||
all-result
|
all-result
|
||||||
(common-util/distinct-by :uuid)
|
(common-util/distinct-by :uuid)
|
||||||
|
@ -252,8 +258,9 @@
|
||||||
(str content (when (not= content "") "\n") (get-db-properties-str db properties))
|
(str content (when (not= content "") "\n") (get-db-properties-str db properties))
|
||||||
content)]
|
content)]
|
||||||
(when-not (string/blank? content')
|
(when-not (string/blank? content')
|
||||||
|
(assert (or (:block/uuid page) uuid))
|
||||||
{:id (str uuid)
|
{:id (str uuid)
|
||||||
:page (str (:block/uuid page))
|
:page (str (or (:block/uuid page) uuid))
|
||||||
:content (sanitize content')
|
:content (sanitize content')
|
||||||
:format format})))))
|
:format format})))))
|
||||||
|
|
||||||
|
@ -264,7 +271,7 @@
|
||||||
{:db/id (:db/id e)
|
{:db/id (:db/id e)
|
||||||
:block/name (:block/name e)
|
:block/name (:block/name e)
|
||||||
:block/uuid id
|
:block/uuid id
|
||||||
:block/page (:db/id (:block/page e))
|
:block/page (:block/page e)
|
||||||
:block/content (:block/content e)
|
:block/content (:block/content e)
|
||||||
:block/format (:block/format e)
|
:block/format (:block/format e)
|
||||||
:block/properties (:block/properties e)})))
|
:block/properties (:block/properties e)})))
|
||||||
|
|
Loading…
Reference in New Issue