Fix page-ref rule which was not bindable and failed fast

- page-ref had a :block/name embedded lookup ref which failed fast.
  datomic advises against this -
  https://docs.datomic.com/on-prem/schema/identity.html#:~:text=You%20cannot%20use%20them%20in%20the%20body%20of%20a%20query%2C%20use%20datalog%20clauses%20instead
- page-ref can handle binding args like last commit for page
- page-ref not failing fast on non-existing pages means that user can get meaningful results
  in more complex queries as seen in test
- Also remove try/catch as there should be no more queries that
  unintentionally cause the 'Nothing found for entity' error
- Also fixed lookup ref in srs cards which can be seen in stacktrace of
  #4576
This commit is contained in:
Gabriel Horner
2022-03-16 15:00:43 -04:00
committed by Tienson Qin
parent 3282d1c766
commit 6b935a8d58
4 changed files with 18 additions and 24 deletions

View File

@@ -13,8 +13,7 @@
[frontend.db.rules :as rules]
[frontend.template :as template]
[frontend.text :as text]
[frontend.util :as util]
[lambdaisland.glogi :as log]))
[frontend.util :as util]))
;; Query fields:
@@ -553,18 +552,12 @@ Some bindings in this fn:
(take @sample (shuffle col)))
identity)
transform-fn (comp sort-by random-samples)]
(try
(query-react/react-query repo
{:query query'
:query-string query-string
:rules rules}
{:use-cache? false
:transform-fn transform-fn})
(catch ExceptionInfo e
;; Allow non-existent page queries to be ignored
(if (string/includes? (str (.-message e)) "Nothing found for entity")
(log/error :nothing-found-error e)
(throw e)))))))))
(query-react/react-query repo
{:query query'
:query-string query-string
:rules rules}
{:use-cache? false
:transform-fn transform-fn}))))))
(defn custom-query
"Runs a dsl query with query as a seq. Primary use is from advanced query"