fix: some queries failed since DB graphs don't have :block/file

One query was failing to load namespaced pages since datascript
fails hard for reverse lookups or {...} syntax on non-existent
attributes.
Also disabled or logged queries that don't have an equivalent
yet for DB graphs
This commit is contained in:
Gabriel Horner
2023-10-27 22:26:42 -04:00
parent 2ce35667c5
commit 3ec7492abd
4 changed files with 26 additions and 15 deletions

View File

@@ -177,7 +177,9 @@
:options {:on-click (fn []
(dev-common-handler/show-entity-data (:db/id page)))}})
(when developer-mode?
(when (and developer-mode?
;; Remove when we have an easy way to fetch file content for a DB graph
(not (config/db-based-graph? repo)))
{:title (t :dev/show-page-ast)
:options {:on-click (fn []
(let [page (db/pull '[:block/format {:block/file [:file/content]}] (:db/id page))]

View File

@@ -1352,15 +1352,16 @@ independent of format as format specific heading characters are stripped"
"Accepts both sanitized and unsanitized namespaces"
[repo namespace]
(assert (string? namespace))
(let [namespace (util/page-name-sanity-lc namespace)]
(let [namespace (util/page-name-sanity-lc namespace)
pull-attrs (cond-> [:db/id :block/name :block/original-name :block/namespace]
(not (config/db-based-graph? repo))
(conj {:block/file [:db/id :file/path]}))]
(d/q
'[:find [(pull ?c [:db/id :block/name :block/original-name
:block/namespace
{:block/file [:db/id :file/path]}]) ...]
:in $ % ?namespace
[:find [(list 'pull '?c pull-attrs) '...]
:in '$ '% '?namespace
:where
[?p :block/name ?namespace]
(namespace ?p ?c)]
['?p :block/name '?namespace]
(list 'namespace '?p '?c)]
(conn/get-db repo)
(:namespace rules/rules)
namespace)))

View File

@@ -7,7 +7,8 @@
[frontend.ui :as ui]
[frontend.util.page :as page-util]
[frontend.handler.property.util :as pu]
[frontend.format.mldoc :as mldoc]))
[frontend.format.mldoc :as mldoc]
[frontend.config :as config]))
;; Fns used between menus and commands
(defn show-entity-data
@@ -61,8 +62,10 @@
(notification/show! "No page found" :warning)))
(defn ^:export show-page-ast []
(let [page-data (db/pull '[:block/format {:block/file [:file/content]}]
(page-util/get-current-page-id))]
(if (get-in page-data [:block/file :file/content])
(show-content-ast (get-in page-data [:block/file :file/content]) (:block/format page-data))
(notification/show! "No page found" :warning))))
(if (config/db-based-graph? (state/get-current-repo))
(notification/show! "Command not available yet for DB graphs" :warning)
(let [page-data (db/pull '[:block/format {:block/file [:file/content]}]
(page-util/get-current-page-id))]
(if (get-in page-data [:block/file :file/content])
(show-content-ast (get-in page-data [:block/file :file/content]) (:block/format page-data))
(notification/show! "No page found" :warning)))))

View File

@@ -309,7 +309,12 @@
[repo tx-report]
(let [{:keys [pages-to-add pages-to-remove-set pages-to-remove-id-set
blocks-to-add blocks-to-remove-set]} (get-direct-blocks-and-pages tx-report) ;; directly modified block & pages
updated-pages (get-indirect-pages tx-report)
updated-pages (if (config/db-based-graph? repo)
;; FIXME: Find a way to do this for DB graphs
(do
(js/console.log "Fetching pages that will have content updated isn't supported in DB graphs")
[])
(get-indirect-pages tx-report))
pages-to-add' (remove (comp db-model/hidden-page? :name) pages-to-add)]
;; update page title indice
(when (or (seq pages-to-add') (seq pages-to-remove-set))