Repository navigation
fix(query): advanced queries skip recycled nodes, text property node values match, :current-page in a zoomed block - #13894
yuxi-liu-wired wants to merge 4 commits into
Conversation
In a DB graph, a text property can hold both plain text and nodes (typing [[x]] in the value). A query such as (property note [[x]]) found only the plain-text values and missed the nodes. A node in a text property is a value block titled [[<uuid of x>]], while the query compares the value with the plain name "x", which only equals the title of a plain-text value block. The ref->val rule now also accepts a value block whose whole title is a reference to a node, with that node's title as the value, as a :node property already does. The new test in query_dsl_test builds a text property with a plain value, a node value and another plain value, and checks that both query forms (page ref and text) find the plain value and the node, and that an unrelated value still matches only its own text. Fixes logseq/db-test#1085
…block A query that uses :current-page returned nothing, or the result for an unrelated page of the same name, after zooming into the block that holds it. Unzooming restored the right result. The page component takes the title of the rendered entity as the current page. When zoomed into a block, that entity is the block, so its own title was used as the page name. page-render-config now uses the title of the block's page when the entity has one. The new test in page_first_paint_test checks the current page title for a page and for a block of that page. Fixes logseq/db-test#1383
After deleting a page or block, an advanced query still counted it inside joins, not clauses and aggregates until the item was permanently deleted from the Recycle bin. For example a "leaf" query (not [?child :streamOf ?parent]) did not return a parent whose only child was recycled. Only the final result was filtered, and so the recycled child just vanished from it. Recycling keeps every attribute on the entity, adds :logseq.property/deleted-at to the root only, and the descendants of the root carry nothing. execute-custom-query ran the query on the full db. It now runs on a filtered db that has no datom of a recycled root or its descendants and none that points to one, as if they were permanently deleted. When nothing is recycled the db is used as is. The filtering needs no new invalidation: the watch keys of a query already include :logseq.property/deleted-at and :block/parent. The new tests (frontend.worker.handler.query-test) recycle a page, and a block with a nested child that holds the reference, check that the parent becomes a leaf, and check that it stops being one once the page is restored. Fixes logseq/db-test#1208
| (let [recycled (recycled-eids db)] | ||
| (if (empty? recycled) | ||
| db | ||
| (let [ref-attrs (ref-attributes db)] |
There was a problem hiding this comment.
🔍 Repeated preparation for advanced queries
With recycled entities present, every execute-custom-query call recomputes the recycled subtree and reference attributes. Multiple query blocks repeat that work for the same snapshot; measure its cost on a representative graph.
Was this helpful? React with 👍 or 👎 to provide feedback.
With recycled entities in the graph, every advanced query block of a page recomputed the recycled subtree and the reference attributes, although they all run on the same db snapshot. The filtered db is now cached per db value in a WeakMap, as logseq.db.common.view does for its exclusion sets. A transaction gives a new db value, so the next query filters again, and the entry goes away with its snapshot. The new test checks that two lookups on one snapshot return the same filtered db, that running a query does not replace it, and that a snapshot after a transaction is filtered again while the older one keeps its own. Refs logseq/db-test#1208
|
Thanks, that was a fair point. The filtered db is now cached per db value (new commit Change. Test.
It fails without the cache ( Measurement. A generated test db: 1000 live blocks on a page, plus 1000 recycled blocks (250 recycled roots with 3 children each, recycled in one transaction), about 17k datoms. Node, test bundle, the box shared with other jobs and run at the lowest priority, so read the ratios, not the absolute values. 15 runs each, median in ms. The benchmark namespace is not committed; it is kept at Cost of the preparation on this graph, per call: One advanced query:
A page with 10 such query blocks on one snapshot (total ms): 538 before, 222 after for the first query; 703 before, 371 after for the second. So the cache removes the roughly 40 ms preparation from every query block after the first. What remains over the no-recycle case (20.1 vs 12.9 ms) is the cost of running on a filtered db (each datom goes through the predicate), which a cache cannot remove. With nothing recycled the cost is unchanged (12.9, 12.6, 12.0 ms for before, miss, hit), as the db is used as is. The remaining first-call cost is mostly the subtree walk (one |
|
Combined into #13871 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there. |
Fixes logseq/db-test#1208, logseq/db-test#1085 and logseq/db-test#1383.
Three independent query fixes on branch
fix/dbtest-query, one commit each (a PR can take them together or split them by commit).logseq/db-test#1085: a text property with nodes could not be queried for those nodes
What the user sees
A text property with multiple values can hold plain text and nodes (
[[x]]).(property note [[x]])found the blocks whose value is the plain textxbut not the ones wherexis a node.Cause
A node in a text property is a value block titled
[[<uuid of x>]]. The query strips[[x]]to the namex, and theref->valrule (deps/db/src/logseq/db/frontend/rules.cljc) compares it with the value block's:block/title, which only equalsxfor plain text.Change
ref->valgets a third branch: a value block whose whole title is a reference to a node ([[<uuid>]]in:block/refs) has that node's title as its value, as for a:nodeproperty. The change does not touchquery_dsl.cljs, so it does not interact with #13871. The extra branch costs one:block/refslookup per property value.Tests
property-default-type-node-value-queriesinfrontend.db.query-dsl-test: a text property with a plainx, a nodexand a plainy.(property note [[x]])and(property note x)both find the plain value and the node;(property note [[y]])finds only theyblock. Fails without the change (the node block is missing), passes with it.logseq/db-test#1383:
:current-pagein a query inside a zoomed-in block used the block's titleWhat the user sees
A query that uses
:current-pagereturns nothing, or the result for an unrelated page with the same name as the zoomed block, once you zoom into the block that holds it. Unzooming gives the right result again.Cause
page-render-config(src/main/frontend/components/page.cljs) takes:current-page-titlefrom the rendered entity. When zoomed into a block, that entity is the block, so its title was used as the page name.Change
:current-page-titleis the title of the entity's:block/pagewhen it has one, else its own title (a page).Tests
query-current-page-is-the-page-holding-a-zoomed-block-testinfrontend.components.page-first-paint-test: a page gives its own title, a block gives the title of its page. Fails without the change ("Milestone"instead of"Host page"), passes with it.logseq/db-test#1208: recycled pages and blocks still affected advanced queries
What the user sees
After deleting a page or block (moved to the Recycle page), advanced queries still counted it inside joins,
notclauses and aggregates until it was permanently deleted. For example, with the issue's "leaf streams" query, deleting the only child of a stream did not make the parent a leaf; the child was hidden from the output, so the parent was simply missing.Cause
Recycling keeps every attribute of the entity (including user node property values), puts
:logseq.property/deleted-aton the root only, and its descendants carry nothing.execute-custom-query(src/main/frontend/worker/handler/query.cljs) ran the query on the full db and only dropped recycled rows from the final output.Change
execute-custom-queryruns the query on ad/filtered db with no datom of a recycled root or its descendants and none that points to one (only for ref attributes: the schema's and the ref-typed properties), as if they had been permanently deleted. The recycled ids are computed once per query from thedeleted-atindex and the:block/parentindex; when nothing is recycled the db is used as is, so graphs without a Recycle bin pay nothing. The query inputs (:current-page,:today, ...) are still resolved on the unfiltered db.Invalidation needs no change: the watch keys of a datalog query already include
:logseq.property/deleted-atand:block/parent(query-watch-keysinrender_resource/query.cljs), and queries with opaque rules watch the whole graph.This covers the advanced (datalog) queries, which is what the issue reports (
:thread-api/query-customand the rendered query blocks). The simple DSL queries (query-dsl/execute-query) are unchanged. Plugin calls to:thread-api/query-customalso no longer see recycled entities.Tests
New
frontend.worker.handler.query-test:custom-query-ignores-recycled-page-testis the issue's reproduction: a recycled child page no longer makes its parent a non-leaf, and a restored child counts again.custom-query-ignores-descendants-of-recycled-block-test: the reference sits on a nested block under a recycled block, which carries nodeleted-atitself.Both fail without the change (
#{"child"}/#{}instead of#{"parent"}), pass with it.Validation
query-test2 failures,query-dsl-test2 failures,page-first-paint-test1 failure (the assertions above). With the fixes: the three namespaces pass (2 tests/8 assertions, 26/112, 6/28).pnpm cljs:run-test) passes with the fixes.deps/dbsuite (pnpm test, nbb) passes: 200 tests, 763 assertions.typosclean.