Repository navigation
fix(db): sync checksum and local graphs, page and tag names, orphaned pages, tag deletion, recycled values, and unreachable code - #13786
Conversation
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
| namespaced-tag? (fn [id] | ||
| (let [e (d/entity db id)] | ||
| (and (ldb/class? e) | ||
| (some #(not= :logseq.class/Root (:db/ident %)) |
There was a problem hiding this comment.
namespaced-tag? treats every class that extends anything other than Root Tag as a namespace child. A top-level class that extends a user class is not a namespace child.
build-new-class sets :logseq.property.class/extends to Root only when that attribute is missing. A class such as Movie that extends Topic keeps #{Topic} and does not also extend Root. After #Movie exists, create of "Movie" with :class? true (typing #Movie again) runs page-exists?, then remove drops Movie, and a second class with that title is inserted. create does not call validate-unique-by-name-and-tags, which otherwise says class titles are unique regardless of what they extend.
Exclude a class only when it is the child segment of a namespace (its parent in :logseq.property.class/extends is the tag named by the title's parent segment), not merely because it extends some tag other than Root.
| ;; The graph starts to sync (upload). Its undo entries were recorded | ||
| ;; without client-op rows, and undo on a synced graph takes an entry's | ||
| ;; ops from its row, so the history ends here, as it does at a restart. | ||
| (worker-undo-redo/clear-history! repo)) |
There was a problem hiding this comment.
local-graph? becomes false as soon as the client-op store has a :graph-uuid. start! writes that id in ensure-client-graph-uuid! when it attaches a remote graph by name, and that path does not set :logseq.kv/graph-remote?. History is cleared only later, here, when the flag flips.
Edits made while the graph was local are undo entries with :tx-datoms and no client-op row. After the id is stored, process-db-op skips the datom replay and calls apply-history-action. There is no row, the result is :missing-history-action, and that reason is not skippable, so clear-history! drops both stacks without restoring the edit.
The same clear also runs before a snapshot upload finishes. create-remote-graph! calls set-graph-sync-metadata!, which transacts the flag, and this listener clears history at that moment. If the snapshot POST then fails, the flag stays set (nothing unsets it) and the local undo entries are already gone.
Replay :tx-datoms until the flag is actually set, or clear history in the same step that stores the remote graph id. Clear only after the snapshot upload succeeds.
| (not (:block/properties page)) | ||
| ;; every page's properties hold its :block/tags | ||
| ;; (Page, Journal): only other properties keep it | ||
| (empty? (dissoc (:block/properties page) :block/tags)) |
There was a problem hiding this comment.
:block/tags is one property key. Its value is the whole tag set: the built-in Page or Journal tag and any user tags. dissoc of that key drops the user tags too, and :block/journal-day is not in :block/properties (public? is false), so an empty journal is property-less after this check.
remove-orphaned-page-refs! then retracts the page. Removing the last [[today]] from a block deletes that empty journal. An empty page whose only extra data is a user tag is deleted the same way, and the tag assignment goes with it. Before this change the cleanup never ran, because every DB page's property map contained :block/tags.
Keep the page when it is a journal, or when any tag other than Page/Journal is present. A user property already keeps it, which the new test covers.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
a85e694 to
9666fc1
Compare
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
9666fc1 to
b270c25
Compare
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
b270c25 to
7b99195
Compare
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
7b99195 to
b4e4bf8
Compare
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
b4e4bf8 to
9189ef1
Compare
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
schema-version->updates-table-test compared the whole migration table, so any migration added upstream (65.35) broke it: it now checks only the entries its mutants change. recycled-entity-values-are-filtered-for-display tested filter-recycled-entity-values with one argument, a private function logseq#13786 rewrites; dropped.
…the bookkeeping-timestamps test
…space A page created by name has no parent, a namespace root has the Library as parent; the uniqueness check compared by raw parent, so renaming the root "Foo" to an existing "Baz" gave 2 top-level pages named Baz (db-test logseq#1346). Pages with no parent or the Library as parent are now checked against each other.
Typing [[Brand new]] in a block creates the page Brand new; deleting the reference from the block again is meant to delete that page when it is empty and nothing else references it (remove-orphaned-page-refs! on save). It never did: get-orphaned-pages keeps a page with (:block/properties page), and in a DB graph every page's :block/properties holds its :block/tags (the Page or Journal tag), so no page ever qualified. Only properties other than :block/tags keep a page now.
With the cleanup working, a save that does not change the title (collapsing a block) must not take the block's pages for orphans: the cleanup runs only when the title changes.
…o next to refs to its blocks
Every JS array has Symbol.iterator, so the iterator clause above it always takes an array first; the clause never runs.
Its test is the same as the clause above, so it is never chosen.
get-all-properties removes recycled properties (those with deleted-at) first, so copying deleted-at onto the result never happens. render-bottom-position-property?: a :node property already passes (not= :default type), so node-many? adds nothing to the or.
…exists! *uuids maps a uuid U to the uuid of the entity found by [:block/uuid U], which is U, so the remap rewrites each lookup ref to itself.
The private fn's only caller passes both arguments.
…s->vec-tree Both callers (editor handler, plugin API block tree) pass a block uuid or nil.
With class? the existing page is looked up among pages tagged Tag
(page-exists? with #{:logseq.class/Tag}), or is a journal page, so it is
never a non-class internal page and the branch never runs.
…e-tx-data block is an entity in every caller, and an entity's cardinality-many value is a set, never sequential, so the check is always false.
ops' falls back to [[:transact ...]] when there are no semantic ops, so (seq ops') is always true.
The atom is read only inside a (comment ...) form, so registering the worker's debounced store has no effect.
Typing DONE (or /todo) while editing the title of a built-in class page,
e.g. the Page class, set :logseq.property/status on the class. Setting a
status, scheduled date or deadline also tags the node #Task when no class
provides the property, but a built-in node keeps its one built-in tag, so
validation rejected the write ("should only have one tag for a built-in
entity") and the user saw only the generic "DB write failed with invalid
data". A local key fuzzer found it through the search dialog's Page result.
disallow-task-properties-on-built-in-nodes refuses those three properties
on built-in nodes with a notification ("Built-in nodes can't be tasks."),
called from set-block-property! and batch-set-property!'s validation, next
to the existing private built-in check. Ordinary pages still become tasks.
task-properties-on-built-in-nodes sets a status on the Page class through
both setters (refused with the notification; before the change both failed
with "DB write failed with invalid data") and on a plain page (it becomes a
task).
A batch of outliner ops that moved blocks into a block and then deleted
that block failed whole ("DB write failed with invalid data"): the moved
blocks came back as stubs holding only :block/order (and :block/parent).
apply-ops! runs the batch on a temp conn and replays its datoms in one
transact!. With :outliner-op :delete-blocks (the editor sets it on a
Backspace merge), expand-delete-blocks-tx ran distinct over that tx-data.
DataScript datoms are equal when e, a and v are, whatever added is, so
the retract of a value the batch had added before (the order and parent
the move gave a block that the delete then removed) was dropped as a
duplicate of the add, and the add was kept.
expand-delete-blocks-tx now keeps the tx-data as it is and dedupes only
the subtree retracts it appends.
move-into-block-then-delete-it-does-not-resurrect-moved-blocks-test runs
the batch, with the moved blocks first as the children and then as the
siblings of the deleted block.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Setting a :number property to text that isn't a number through batch-set-property! (the property value picker of the add-property dialog) went through convert-ref-property-value, where parse-double returned nil and the write failed as "Property value must be not nil" (a raw worker error). It now uses fail-parse-double like convert-property-input-string, so the user gets "Can't convert "x" to a number." and nothing is written. A local key fuzzer reached it by typing "#status" into a number property's value picker. batch-set-property-refuses-a-value-it-cant-convert: the write is refused with a notification and the block keeps no value; it failed with the raw error before.
:thread-api/reorder-display-property (dragging a property to a new place in a block's property list) returned the result of ldb/transact!, a tx report, which the worker can't send back to the renderer: the call failed with "Cannot write TxReport" although the reorder was saved. It returns nil now. It is the only thread api whose result is a transact call (scripts/thread-api-tx-returns.mjs). A local key fuzzer that drags at random hit it. property-reorder-test: the reorder is saved and the call's result can be written as transit; it failed with the tx report before.
… break the graph's open Converting a tag to a page left the tags that extend it pointing at the page. When the page was recycled and the 30-day recycle GC removed it, those tags lost their only parent, the GC write failed validation, and since the GC runs while a graph opens, the graph never opened again (logseq#13877). - `db-class/detach-child-classes-tx`: tags extending a parent that stops being a tag (or is retracted) drop it; one left with no parent extends Root, as when a tag is deleted. - `convert-tag-to-page` uses it, so new conversions leave no stale parent. - The recycle GC and permanent delete use it for every page they retract, which repairs graphs converted before this fix. - A GC failure while the graph opens is logged instead of stopping the open. Fixes logseq#13877
It is used outside deps/db, by the outliner's recycle and the worker's tag-to-page conversion.
Undo of a block delete on a graph without sync must give the blocks that referred to the deleted block their ((uuid)) reference and refs back (logseq/db-test#1325), and must put a deleted block back with its page link stored by uuid, not by name (logseq/db-test#1326). The PR fixed both by replaying the transaction's own datoms, but no test pinned either. Both tests fail on origin/master's undo_redo.cljs, sync/apply_txs.cljs and pipeline.cljs and pass with the PR's.
The tests of undo and redo replaying a change's datoms on a local graph sat at the end of undo_redo_test.cljs, where master keeps adding undo tests, so each new master test there conflicted with this PR. They now live in frontend.worker.undo-redo-local-replay-test with copies of the fixture and the helpers they use; undo_redo_test.cljs keeps only this PR's edits to its existing tests.
Since master's logseq#13449 the undo of a page create recycles the page and its new namespace parents and tags, and redo restores them with their uuids; master pins this with tests on a local graph. This branch's local-graph undo replayed the create's tx datoms instead, which retracts the page, so those tests failed after the rebase. A page create on a local graph now keeps its client-op row and semantic ops, and its undo and redo take the semantic path as on a synced graph (replays-tx-datoms?); every other local transaction still replays its datoms. The redo-create-page test no longer marks its graph synced, and the pipeline replay test expects the page recycled after the undo. That pipeline replay test also changed Movie's parent tag to Root with set-block-property; since master's logseq#13287 adding Root next to another parent is ignored, so the change recorded no undo entry. It now removes the parent tag, which gives Movie the Root tag as parent.
…ted as orphaned Saving a block compares its old and new refs and retracts pages it no longer refs. The new refs were read by :block/name or :db/id only, so a ref given as a [:block/uuid id] lookup (master's input path gives one for a `[[uuid]]` link in the title) counted as dropped. With this PR's orphan check, which no longer keeps a page only because its properties hold its tags, the save then retracted the very page it links and failed with "Nothing found for entity id" (master's cli-page-block-and-missing-uuid-links, in the nightly build). A lookup ref now has its name read from the db.
Reverts the orphan check of 2c8e758 ("an edit deletes the empty page it no longer references"). Master's CLI E2E case block-update-page-refs creates Alpha with `upsert page`, links and unlinks it from a block, and expects the same Alpha (same uuid) afterwards; with the change the unlink deleted Alpha and a later [[Alpha]] made a new page. Master's pinned behaviour wins: a page whose :block/properties hold its tags is kept again. The orphaned-pages test now pins that the empty page stays.
This PR combines #13545, #13620, #13626, #13675, #13686, #13728, #13739, which change the same files, into one branch on current master so they no longer conflict with each other. Each part is unchanged except where two of them touched the same lines.
#13545: perf(sync): cheaper checksum; undo and no sync rows on local graphs
This brings #13469, #13470, #13466 and #13478 into 1 pull request, so they merge once. They share test files (
db_sync_test.cljs,db_sync_sim_test.cljs,undo_redo_test.cljs) and the undo and pipeline code, so each merge made the others conflict. The branch is on current master. Each part keeps its own commits, changed only where a test conflict had to be resolved, so the review can go commit by commit. The old pull requests are closed with a link here; their review threads stay there.Commits, in order:
test(sync): pin recompute-checksum to a reference(perf(sync): recompute the checksum in 1 walk of :eavt #13469)test(sync): give the uuid churn test a real tx id(perf(sync): recompute the checksum in 1 walk of :eavt #13469)perf(sync): read each entity's datoms once(perf(sync): recompute the checksum in 1 walk of :eavt #13469)perf(sync): read parent and page uuids from a map(perf(sync): recompute the checksum in 1 walk of :eavt #13469)perf(sync): walk :eavt once for the full recompute(perf(sync): recompute the checksum in 1 walk of :eavt #13469)perf(sync): write the checksum in 1 transaction(perf(sync): write the checksum in 1 transaction #13470)fix(undo): replay the tx datoms on local graphs(fix(undo): replay the tx datoms on local graphs #13466)perf(sync): keep no sync record on local graphs(perf(sync): keep no sync record on local graphs #13478)test(sync): fit the checksum tests to local graphs, new: with perf(sync): keep no sync record on local graphs #13478 every graph of the sync tests is marked synced unless it asks to stay local, so the checksum tests of graphs that do not sync (from perf(sync): keep checksum only on remote graphs #13476) ask for a local graph, and the reopen test of fix(db): restore :max-tx of pipeline transactions #13468 opens its reopened graph as a local one, since it is marked synced already through its storage.test(undo): run the cardinality undo tests synced, new: the 2 tests of fix(outliner): do not revert many to one on undo #13526 check the inverse op of a one-to-many property change, which after fix(undo): replay the tx datoms on local graphs #13466 runs only on a synced graph.Undo of a one-to-many change on a local graph
This is a behavior difference to decide on. #13526 keeps
:db.cardinality/manywhen a one-to-many change is undone, so that the inverse op does not throw or clear the history. With #13466, undo on a graph that does not sync replays the change's recorded datoms instead of an inverse op: the undo gives the property:db.cardinality/oneback, and the block its single value as it was, and redo makes it:manyagain with the value in a set. Nothing throws and the history stays. On a synced graph the undo goes through the inverse op of #13526 and keeps:many. In the run of #13526's 2 tests on a local graph with this branch, the failing assertions were exactly these, in each test: no inverse op,:oneafter undo, a single value after undo. In the first test the value's title was still "text 1" and the redo assertions passed; the second test has no redo. If:manyshould survive undo on local graphs as well, the replay would need an exception for this change.Tests
The whole unit suite on commits 1 to 9 (master
68a68263bplus these commits), with thedb-worker-nodetarget compiled: atTZ=Etc/GMT+122585 tests, 12924 assertions; atTZ=Pacific/Kiritimati, the date-dependent namespaces, 1537 tests, 9433 assertions. The only failures were the 2 tests of #13526 described above (3 assertions each, in both zones). With commit 10,frontend.worker.undo-redo-test(62 tests),frontend.worker.db-sync-test(242) andfrontend.worker.db-sync-sim-test(21) have 0 failures in both zones.The descriptions of the parts follow, as each pull request had them.
#13469: perf(sync): recompute the checksum in 1 walk of :eavt
What changes
recompute-checksum(deps/db-sync/src/logseq/db_sync/checksum.cljs) computes the whole-graph sync checksum from scratch. The worker runs it when it opens a graph whose stored checksum does not cover the graph's:max-tx(#13415), before a snapshot upload, and for the checksum diagnostics;update-checksumruns it when the e2ee flag changes or the stored checksum is not valid. On a graph of 157,614 checksum-eligible entities (1,326,567:eavtdatoms, imported from a file graph), the release build took 3.39 s with the graph in memory and 5.83 s with its index nodes still in sqlite. This branch takes that to 0.25 s and 2.81 s, and the recompute returns the same value.On master, for each entity in the
:block/uuidindex, the recompute ran 5d/datomslookups for the eligibility check, 2 more for the entity's uuid and datoms, and 1 per parent and page tuple for their uuids. It then built a set of[uuid attr value]tuples and a[fnv djb]vector per tuple and per digest step. A CPU profile of the in-memory recompute on master (release build, 1 run, 1 ms sampling, 3,509 ms window) has 1,633 ms in index seeks (-sliceand its comparators), 419 ms in hashing and 381 ms in garbage collection.The commits:
test(sync): pin recompute-checksum to a reference: a reference recompute written from the definition in the test file, compared withrecompute-checksumon 37 graphs (listed under Tests), and the value on 1 fixed graph pinned to the one master gives.test(sync): give the uuid churn test a real tx id:incremental-checksum-matches-recompute-with-duplicate-block-uuid-tx-churn-testgave its datoms tx 200, below datascript's tx0 (536870912). Such a datom is missed by(d/datoms db :eavt 3)andd/entityand returned by a walk of the whole:eavtindex, so the test's outcome depended on which read each checksum path used. It now uses the next tx id, and passes on master.perf(sync): read each entity's datoms once: 1:eavtread per entity answers the eligibility check and gives the tuples. The eligibility check ofupdate-checksumreads the same way.perf(sync): read parent and page uuids from a map, filled by 1 walk of the:block/uuidindex.perf(sync): walk :eavt once for the full recompute: an entity's datoms are adjacent in:eavt, so 1 walk of the whole index reads each entity's eligibility and checksum datoms as it passes them, and folds each tuple's digest into 2 running sums, with the entity's uuid prefix folded once per entity. An entity still counts once per:block/uuiddatom, as when the recompute walked that index. An entity with a repeated attribute goes through the tuple set as before, since 2 of its datoms can give the same tuple (2 parents with equal uuids).Recompute time on that graph, standalone db worker, median (range) of 3 runs per build. Cold is the first recompute after the start, with every index node loaded from sqlite. Warm is the later recomputes of the same runs that loaded no index node, 4 to 6 values per build. Each build is the source tree of the commit named.
16c4ed1a0): release cold 5.83 s (5.42 - 6.59), warm 3.39 s (2.45 - 3.48); dev cold 6.70 s (6.56 - 7.66), warm 4.16 s (4.15 - 4.23).Worker start on the graph as imported, which recomputes the checksum at start (
fix/restore-max-txremoves that recompute), from the worker's first log line to its ready line, 3 runs per build: master release 5.75 s (5.61 - 7.22) and dev 7.90 s (7.00 - 8.24); this branch release 2.71 s (2.41 - 2.98) and dev 3.10 s (2.02 - 3.27). The cold recompute still loads the graph's 70,194 index nodes from sqlite, which this branch does not change.Per transaction,
update-checksumtakes about the same time as on master (release build, median (range) of 3 runs): 0.12 ms (0.12 - 0.13) against 0.14 ms (0.11 - 0.14) on master for a 1-block save, 11.0 ms (10.9 - 11.2) against 10.9 ms (10.5 - 11.0) for a 200-block insert.The value, on the same graph: every recompute of every build above gave
9b54a1fd6dc28b43, the value master gives. On the head's build that is 24 recomputes in 12 runs, dev and release. After 6 edits on that graph (save, insert, move and delete of 1 block, insert and delete of 200 blocks), the checksum the listener kept incrementally equals a full recompute in all 6 runs on the head's build.Tests
logseq.db-sync.checksum-test, run fromdeps/db-syncsince it reads its fixtures from there: 29 tests, 116 assertions, 0 failures on master'schecksum.cljswith this branch's tests, and on commits 3, 4 and 5.incremental-checksum-matches-recompute-on-rebased-retract-entity-log-repro-testfails as well (3 failures).bb99d466953b7166against incrementald74eeb69c5a85c5b). With the next tx id it passes on master and on this branch.frontend.worker.db-sync-test233 tests, 2222 assertions;frontend.worker.sync.client-op-test6 tests, 22 assertions: 0 failures.TZ=Etc/GMT+12(2502 tests, 12497 assertions) and its time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1469 tests, 9056 assertions): 0 failures, 0 errors. Its runner leaves outlogseq.db-sync.*, hence the separate run above.deps/db-sync: 0 errors, 0 warnings.#13470: perf(sync): write the checksum in 1 transaction
What changes
After every transaction, the db listener stores the new sync checksum and the tx it covers in the graph's client-ops database (
update-local-checksum,src/main/frontend/worker/sync/client_op.cljs). The 2 keys went in 2 upserts, each its own sqlite autocommit. That database runs in WAL mode withsynchronousFULL (read withPRAGMA synchronouson a graph's client-ops file), so each autocommit is a synced write. The 2 upserts now run in 1 transaction throughsqlite-with-tx!, which the file already has, so each transaction pays 1 synced commit, and the 2 keys change together.In the node worker,
sqlite-with-tx!calls the connection wrapper'stransaction(wrap-node-sqlite-dbinsrc/main/frontend/worker/platform/node.cljs), which runs the function betweenBEGINandCOMMIT.Timings on a graph of 157,614 checksum-eligible entities (imported from a file graph), standalone db worker, median (range) of 3 runs per build:
update-checksumplus the write), which the dev build logs, master against this change: 1-block insert 17.5 ms (17.0 - 17.8) against 10.0 ms (9.4 - 10.0), 1-block move 17.2 ms (16.4 - 25.0) against 9.2 ms (8.5 - 10.0), 1-block delete 17.2 ms (16.4 - 19.9) against 9.6 ms (9.2 - 10.3), 200-block insert 34.8 ms (33.7 - 36.6) against 28.2 ms (26.1 - 29.3), 200-block delete 33.1 ms (32.7 - 36.2) against 25.0 ms (24.6 - 27.4). The first transaction after the start, a 1-block save, takes 18.0 ms (17.2 - 24.0) on master and 17.7 ms (17.0 - 18.7) with this change.The builds with this change also carried the commits of
perf/checksum-one-walkandfix/restore-max-txand 1 change to the sqlite read path. A build with the recompute changes and without this commit wrote in 16.8 ms (16.2 - 17.1) release and 17.2 ms (16.6 - 17.6) dev, 3 runs each, the same as master.Tests
checksum-and-covered-tx-written-in-1-transaction-testinfrontend.worker.sync.client-op-test: counts the calls of the database'stransactionduringupdate-local-checksumand reads both keys back. On master it fails (1 failure: 0 calls). With this change it passes. The test's database is better-sqlite3 in memory, as in the rest of that namespace.frontend.worker.sync.client-op-test7 tests, 25 assertions;frontend.worker.db-sync-test233 tests, 2222 assertions;logseq.db-sync.checksum-test(run fromdeps/db-sync) 28 tests, 78 assertions: 0 failures.TZ=Etc/GMT+12(2503 tests, 12500 assertions) and its time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1469 tests, 9056 assertions): 0 failures, 0 errors.#13466: fix(undo): replay the tx datoms on local graphs
What changes
On a graph without sync, undo and redo now replay DataScript's own record of each change, as logseq/db-test#1339 proposes: the tx report's datoms, each flipped and last first for undo, as recorded for redo. Synced graphs keep the semantic inverse ops.
Today undo replays an inverse op built from the change's label (
build-inverse-*inconstruct.cljc). Where an operation does more than its label says, undo loses the difference (#13464). Deleting a property or a tag is the clearest case. On a graph without sync (:logseq.kv/graph-remote?not set), nothing can land between a change and its undo, so the exact undo is the change's own datoms, reversed, whatever the operation.It fixes, on graphs without sync:
Each has a regression test in
frontend.worker.undo-redo-testthat fails on master. It also fixes the 2 undo bugs the property test of #13461 found once it saw links:((uuid))references back. Pinned byfrontend.worker.undo-redo-test/local-graph-undo-of-block-delete-restores-block-references-test(fails on master's undo).frontend.worker.undo-redo-test/local-graph-undo-of-block-delete-restores-page-links-by-uuid-test(fails on master's undo).How
gen-undo-ops!keeps, on a graph without sync, the tx report's datoms as[e a v added], entity ids unchanged, in DataScript's order (:tx-datomsof the entry). The report is the oneldb/transact!hands to its listeners, which already holds what the worker pipeline added in the same transaction (tag templates, refs, revision stamps). The datoms stay in memory with their entry, like the rest of the undo stack.apply-history-action!gives a history action, so the undo is recorded as a client-op row as before, plus:undo-redo/replay-tx-datoms?.transact-pipelinederives nothing: the datoms already hold what it derived for the change. Without this, each redo of a block tagged with a class that has a template inserted the template again.ldb/transact!also skipsexpand-delete-blocks-txandupdate-refs-historyfor it: the datoms are the whole change, anddistinctinexpand-delete-blocks-txdropped a retraction that repeats after its opposite, which left a revision stamp on a deleted block.:block/tx-idon what an undo or redo changes, so the renderer refreshes those blocks. The entry pushed on the opposite stack therefore holds the undo's or redo's own datoms, stamps included, and the next undo or redo is again the exact inverse of the last transaction.:block/tx-idretracts the stamp whatever its value: the undo of a later change can restamp an entity of an earlier one (the pages tagged with a tag whose parent changed).Builds on #13462
The first commit of this branch is #13462's. Without it a full undo stack (250 entries) drops its newest half, so the datoms of the entries below the hole no longer match the graph, and a replay that yields an invalid entity is refused.
all-core-outliner-ops-local-undo-redo-random-sim-test(1000 operations on a graph without sync) then fails with "undo-all exceeded max steps".Tests
frontend.worker.undo-redo-test, 13 new tests: 1 per issue above, the exact order key after undo of a move, rounds of undo and redo of a property delete and of a block delete with the worker pipeline registered, undo of a page create after the undo of a tag change with the pipeline registered, the tag template added once per redo, a failed replay that keeps the history, and the semantic path on a synced graph (also for entries recorded before the graph synced). On master, 11 of the 13 fail (19 failures). Each piece of the fix has a test that fails without it: the pipeline key (2 failures), the replay's own datoms on the opposite stack (10), the stamp rule (3), theldb/transact!skip (2).:logseq.kv/graph-remote?, as upload and download do: 6 inundo-redo-test(fake worker results, create-page into Recycle, apply-template re-inserting new blocks, missing history rows), the 9 server-based tests ofdb-sync-sim-testthat undo or redo (create-synced-conn), and the 2 template upload tests after rebase indb-sync-test.TZ=Etc/GMT+12andTZ=Pacific/Kiritimati:frontend.worker.undo-redo-test56 tests, 302 assertions;frontend.worker.db-sync-test232 tests, 2221 assertions;frontend.worker.db-sync-sim-test21 tests, 427 assertions;frontend.worker.pipeline-test,frontend.worker.db-core-test,frontend.worker.db-worker-test,frontend.undo-redo-test,frontend.handler.history-test; 0 failures.TZ=Etc/GMT+12(2516 tests, 12581 assertions) and the time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1483 tests, 9140 assertions): 0 failures, 0 errors.#13478: perf(sync): keep no sync record on local graphs
What changes
This builds on #13466 and is stacked on its branch.
After every local transaction, the db listener stores the change as a client-op row: its normalized and reversed datoms, its forward and inverse outliner ops, pending (
persist-local-tx!insrc/main/frontend/worker/sync/apply_txs.cljs). That is 1 synced sqlite commit per edit, on every graph. With #13466, undo and redo on a graph without sync (:logseq.kv/graph-remote?not true) replay the tx datoms the undo entry keeps, and on such a graph nothing reads the row any more. Every reader of these rows:gen-undo-ops!, throughhistory-action-ops-by-tx-id), andapply-history-action!reads a row by tx id for the semantic undo and redo. On a graph without sync, fix(undo): replay the tx datoms on local graphs #13466's undo and redo replay the entry's datoms and use neither.flush-pending!), the rebase of pending rows under remote txs (apply-remote-txs!), the rollback after a reject (rollback-and-mark-failed-txs!) and the acks (mark-pending-txs-false!) run only on a sync connection.upload-graph!insync/upload.cljs) sends a snapshot of the whole graph, then marks every pending row done without sending it (clear-pending-txs!).db-sync-status, which the CLI'ssync statusprints, and the sync indicator of a live connection), the cleanup every 3 hours (cleanup-finished-history-ops!, which deletes only rows with pending 0, so on a graph that never synced it deletes none), and the client-ops export for debugging.Today a graph without sync keeps 1 row per edit, forever. On a new graph after the 2 sessions measured below (180 measured edits and their setup): 194 rows, all pending, holding 0.79 MB (insert 2.5 KB, delete 1.7 KB, save 1.6 KB per row; the first row, 413 KB, is the new graph's initial data), in a 1.0 MB file.
With this change, a local transaction on a graph that is not remote after it, the transactions of undo and redo included, gets its undo entry where it makes one and nothing in the client-ops database: no reversed datoms, no derived outliner ops, no row, no pending count.
gen-undo-ops!reads no row there; the entry keeps:tx-datomsas in #13466. On a remote graph the path is as before. The condition is the onehandle-local-tx!had from de1c58b (rows only on remote graphs) until c3df967, "fix: undo/redo doesn't work for local graphs", which dropped it when undo came to read the row.A graph uploaded in the middle of a session holds undo entries recorded without rows. On a synced graph undo takes an entry's ops from its row, and without the row
apply-history-action!returns:missing-history-action, which logs an error and clears the history at that undo. The transaction that makes a graph remote (the upload'sset-graph-sync-metadata!) now clears the undo and redo history inhandle-local-tx!, so the history ends at the upload instead of at the first undo after it. ADR 0011 makes the client-op row the source of truth for DB undo history, which it still is on a synced graph, and asks that a stack entry whose row is dropped be invalidated rather than left dangling; the stacks already end at a restart ("Session boundary"). This replaces #13466's rule that entries recorded before an upload take the semantic ops (their rows existed then). Keeping the datom replay for those entries after the upload would record each such undo on the synced graph as a row of datoms without semantic ops, the raw undo row that ADR 0011 moves away from.Rows written before this change on a graph without sync are left as they are, pending: nothing here deletes them, and the status keeps counting them. The first upload marks them done as today, and the cleanup then deletes them.
A graph syncs once it has the flag or a remote graph id in its client-ops database (
local-graph?inundo_redo.cljsreads both).start!can connect sync to a graph without the flag when a remote graph has the same name (<resolve-start-graph-id), and records that graph's id; a graph downloaded before 4ce4aed ("download remote graph should set sync metadata too") has the id and no flag. Both keep their rows as before. The history ends only when the flag is set, at an upload or download.On a graph without sync the listener builds no upload data: the normalized and reversed datoms are computed only on the synced path. A transaction of attributes sync ignores still makes no undo entry, as before.
Measured on the desktop app, release builds of #13466 (
a61ab13b5) and this branch, a new graph without sync each, 2 sessions of 30 cycles per build (the order #13466, this branch, this branch, #13466), median (range) over the 60, key to the next editor focused (delete) or to the editor gone (save):Tests
frontend.worker.db-sync-test:local-graph-edit-writes-no-sync-record-test: an edit on a graph without sync writes no row and no pending count; its undo entry holds:tx-datoms, and undo and redo restore the title and write no row either. On fix(undo): replay the tx datoms on local graphs #13466 it fails (4 failures: 1 row after the edit, pending count 1, 3 rows after the undo and redo).local-graph-keeps-existing-sync-records-test: a pending row written before this change stays, pending, after an edit and a cleanup run, and no row joins it. On fix(undo): replay the tx datoms on local graphs #13466 it fails (3 failures: a second pending row).upload-ends-undo-history-recorded-without-sync-record-test: 2 edits and an undo on a graph without sync, thenupload-graph!with its network calls replaced, through the app's db listener: after the upload the undo and redo stacks are empty and undo changes nothing; an edit after the upload writes its row, and its undo goes through that row. On fix(undo): replay the tx datoms on local graphs #13466 it fails (6 failures: 3 rows before the upload, both stacks kept, and the undo after the upload undid an edit from before it).remote-graph-edit-writes-sync-record-test: an edit on a remote graph writes its row with the semantic ops, and the undo entry takes them from it. Passes on fix(undo): replay the tx datoms on local graphs #13466 too.graph-with-a-remote-id-writes-sync-records-test: a graph with a remote graph id and no flag (attached by name, or downloaded by an older version) writes its pending row and an entry without:tx-datoms.local-graph-edit-builds-no-upload-data-test: an edit on a graph without sync calls nonormalize-tx-data, and makes its undo entry.frontend.worker.db-sync-test,with-datascript-connsmarks its graph remote (with this change and without that, 82 of its tests fail: they read the rows of edits made on graphs built without the flag), the 3 new tests of graphs without sync usewith-local-graph-conns, and 3 tests that build their tx report before that helper mark the graph first. Infrontend.worker.undo-redo-test, 7 tests of the semantic ops an entry takes from its row mark the graph synced. Infrontend.worker.db-sync-sim-test, 5 client tests usecreate-synced-conn. fix(undo): replay the tx datoms on local graphs #13466'ssynced-graph-undo-replays-semantic-ops-testkeeps its synced part; its part about entries recorded before an upload is replaced by the upload test above.with-datascript-connsno longer resets the conns and the undo history when a later test has installed its own conn. In a run of the namespace, the cleanups of 8 async tests that calldonebefore the helper's cleanup ran while a later test was running; the one ofpull-ok-without-checksum-is-accepted-testemptied the client-ops conn in the middle of the new upload test, which passed when run alone.frontend.worker.outliner-undo-property-testfrom its branch, not in this pull request), on a graph without sync, its known-bug list off, every violation counted: seed 20260926, 300 sequences, 0 violations; seed 4242, 300 sequences of up to 20 operations, 0 violations. fix(undo): replay the tx datoms on local graphs #13466 gives the same 0 and 0 on the same runs.TZ=Etc/GMT+12andTZ=Pacific/Kiritimati:frontend.worker.undo-redo-test56 tests, 301 assertions;frontend.worker.db-sync-test236 tests, 2255 assertions;frontend.worker.db-sync-sim-test21 tests, 427 assertions;frontend.worker.sync.client-op-test6 tests, 22 assertions;frontend.worker.db-listener-test14 tests, 51 assertions;frontend.worker.pipeline-test42 tests, 193 assertions;frontend.worker.db-core-test147 tests, 1601 assertions;frontend.worker.db-worker-test,frontend.worker.sync.restart-test,frontend.undo-redo-test,frontend.handler.history-test: 0 failures, 0 errors.TZ=Etc/GMT+12(2520 tests, 12614 assertions) and its time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1487 tests, 9173 assertions): 0 failures, 0 errors.Allow edits from maintainers.
#13620: fix(page): a namespace root and a page with no parent share one name space
Part of logseq/db-test#1346 (its second case; the first, a rename there and back being refused, no longer happens on master since #13516).
Create the page "Baz", then "Foo/Bar" (the Library now holds "Foo"). On the page "Foo", change the title to "Baz": it is accepted, and the graph has 2 top-level pages named "Baz", one of them in the Library. Renaming "Baz" to "Foo" is accepted the same way. Renaming any other page with no parent to "Baz" is refused, and Cmd+K on "Baz" opens the existing page.
validate-unique-for-pageindeps/outliner/src/logseq/outliner/validate.cljsscopes the name check by the raw parent: a page with no parent is compared with other pages with no parent, a page with a parent only with its siblings. Top-level pages come in 2 kinds: a page created by name has no parent, a namespace root has the Library as its parent. So a namespace root and a page with no parent never meet in the check.Both kinds now count as top-level: a page whose parent is the Library is compared with pages with no parent and pages under the Library, and the other way around. Pages inside a namespace keep being compared with their siblings only, so a top-level page may still share a name with a namespace child ("Baz" and "Foo/Baz").
New test
rename-is-checked-among-top-level-pagesindeps/outliner/test/logseq/outliner/page_test.cljs: a namespace root renamed to a top-level page's name and a top-level page renamed to a namespace root's name are refused (both accepted on master); a top-level page renamed to a namespace child's name and back, and siblings in a namespace, behave as before. The outliner tests indeps/outliner(158 tests) andfrontend.handler.db-based.page-test,frontend.modules.outliner.pipeline-test,frontend.worker.undo-redo-test,frontend.worker.outliner-undo-property-test,frontend.worker.db-sync-test,frontend.worker.db-sync-sim-test(with its ^:long tests),frontend.worker.db-listener-test,logseq.api.editor-testpass.#13626: fix(tag): creating a tag does not return a namespaced tag of that name (dropped from this branch)
Dropped: a namespace child tag ("Baz" in
#Foo/Baz) is built with:logseq.property.class/extendsFoo, the same linkaddTagExtendsmakes, so the data cannot tell "Baz inside Foo" from "a tag that extends Foo". This change left out every tag extending a tag other than Root Tag, which broke master'stag-inheritance-schema-and-object-view-test(clj-e2e graph-properties):#SampleChildin a block created a second SampleChild instead of tagging with the one extending SampleParent. db-test#1345's tag side needs a namespace marker on the tag before a fix can tell the two apart. Kept below for the record.Part of logseq/db-test#1345 (the tag side; the page side is #13625).
Create the tag "#Foo/Baz", then the tag "#Baz": the second create returns Foo/Baz's "Baz" and no top-level tag "Baz" exists. In the other order, "#Baz" then "#Foo/Baz", both tags exist, and tags in different namespaces may share a name (db-test#466).
createindeps/outliner/src/logseq/outliner/page.cljslooks for an existing tag withldb/page-exists?and#{:logseq.class/Tag}, which matches the exact title among all tags, whatever they extend, and returns the first. Pages are already checked for a parent before being reused.When the title has no namespace,
createof a tag now leaves out tags that extend a tag other than Root Tag, i.e. tags inside a namespace. A top-level tag with the title is still reused, and a create of a namespaced title goes throughsplit-namespace-pagesas before.New test
create-tag-does-not-return-a-namespaced-tag-of-that-nameindeps/outliner/test/logseq/outliner/page_test.cljs: "Foo/Baz" then "Baz" as tags gives a new tag Baz extending Root Tag, and creating "Baz" again returns it. On master the second create returns Foo's Baz; with the change it passes. The outliner tests indeps/outliner(158 tests) andfrontend.handler.common.page-test,frontend.handler.page-test,frontend.worker.handler.page-test,frontend.handler.db-based.page-test,frontend.components.cmdk-test,frontend.worker.undo-redo-testpass.#13675: fix(db): an edit deletes the empty page it no longer references (reverted)
Reverted on 2026-11-12 (a1d33a7). Master's CLI E2E case
block-update-page-refs(added 11-11) creates Alpha withupsert page, links and unlinks it from a block, and expects the same Alpha (same uuid) afterwards; with this change the unlink deleted Alpha and a later[[Alpha]]made a new page. Master's behaviour (a page is kept when nothing references it) wins, so the orphan check is master's again andorphaned_pages_test.cljsnow pins that the empty page stays. Whether an implicitly created, still empty page should go when its last link is removed is a product decision; it would need to tell such a page apart from one created on its own. The lookup-ref fix below (1a9b69f) stays: it is correct on its own.The original section:
Typing
[[Brand new]]in a block creates the page "Brand new". Deleting that reference from the block again is meant to delete the page when it is empty and nothing else references it:save-blockcallsremove-orphaned-page-refs!for that. It never deletes anything.ldb/get-orphaned-pageskeeps a page that has(:block/properties page). In a DB graph,:block/properties(entity-plus/get-properties) lists every property attribute of the entity, and:block/tagsis one: every page has the Page (or Journal) tag, so every page has properties and none ever qualifies.The fix: only properties other than
:block/tagskeep a page.Test:
src/test/logseq/outliner/orphaned_pages_test.cljs. An edit from[[Kept]] [[Dropped]]to[[Kept]]deletes the empty page Dropped and keeps Kept (fails on master: Dropped stays); a page with a property (a checkbox set on it) is kept; a save without a title (collapsing the block) keeps the pages the block references, since the cleanup runs only when the title changes. The test is in the app's test build because the outliner library's nbb run does not compute:block/properties. The editor, undo/redo, page, outliner, pipeline and DB core test namespaces pass with the change.#13686: fix(delete): deleting a tag page turns refs to it into its title, also next to refs to its blocks
Deleting a tag (or property) page leaves the deleted page's
[[uuid]]in any block that references the page next to one of the page's own blocks. Example: a block says "see [[Foo]] and [[fb]]", where Foo is a tag and fb a block on Foo's page. After deleting the tag Foo, the block readssee [[<Foo's uuid>]] and fb: a reference to a node that no longer exists, instead ofsee Foo and fb.Cause:
outliner-page/delete!sends the page's ref rewrite (the block's title with[[Foo]]turned into "Foo") and the retracts in one transaction.ldb/transact!then appendsdelete-blocks/update-refs-history, which writes the same block's title again, computed from its title before the transaction with only the retracted blocks replaced (fb); pages are notblock-entity?, so[[Foo]]stays. Two values for the cardinality-one:block/titlein one transaction: the later one wins. When the block references only the page, both rewrites agree, which is why the common case works.Fix:
build-retracted-txalso turns refs to pages retracted in the same transaction into their titles, so its rewrite agrees with the page's own. Which entities count as blocks (for expanding a delete to children) is unchanged.Test:
logseq.outliner.delete-tag-page-refs-test(app test build: the title rewrite reads:block/raw-title, an entity-plus lookup nbb does not have) deletes a tag page withoutliner-page/delete!and checks a block referencing the page and its block ("see Foo and fb") and a block referencing only the page ("see Foo"). On master it fails on the first; with the fix it passes. Also with the fix:logseq.db.common.delete-blocks-test,logseq.db-test(33 tests),logseq.outliner.page-test,logseq.outliner.property-test(56 tests) under nbb, andfrontend.worker.pipeline-test(45 tests, including page deletes) in the app build: 0 failures. Lint as in CI fordeps/dband the app.Found by mutation testing:
andtoorinblock-entity?made no existing test fail, and the changed version gave "see Foo and fb".#13728: fix(property): leave recycled values out of a block's displayed properties
What goes wrong
Move a page to the Recycle bin while another page or block uses it as a node property value. The property area still shows that property with the recycled page as its value. When the recycled page is one of several values, it still appears among them. Recycled values are supposed to be left out of the property area, and a property whose only values are recycled is supposed to be hidden.
Cause
src/main/frontend/worker/handler/property.cljs,display-properties: for a stored block,display-properties-for-blockreads each ref value as a summary map fromplain-value/ref-value->summary. That map carries no:logseq.property/deleted-atand no parent.sanitize-property-values-for-displaycallsldb/recycled?on the summary, so it never finds a recycled value.Fix
Check whether a value is recycled on its entity, looked up by
:db/id, incontains-recycled-entity-value?andfilter-recycled-entity-values. A value without a:db/idis still checked as given.Test
frontend.worker.handler.property-test/display-properties-of-a-stored-block-leaves-out-recycled-valuesrecycles a page used as a single-value node property and as one of two values of a many-value node property. It expects the first property to be left out and the second to keep only the live value. Both assertions fail on master and pass with the fix.#13739: chore: remove code that never runs or never changes a result
Removes code that never runs or never changes a result. Each removal is its own commit, with the reason in its message; behaviour is unchanged.
get-sql-rows(db-sync and publish copies): the(array? result)clause. Every JS array hasSymbol.iterator, so the iterator clause before it always takes an array first.search-fuzzy/score: acondclause whose test repeats the clause before it.get-all-properties: copying:logseq.property/deleted-atonto each result. Recycled properties (those withdeleted-at) are removed first.render-bottom-position-property?:node-many?. A:nodeproperty already passes(not= :default type)in the sameor.ensure-built-in-data-exists!: the*uuidsremap. It maps a uuid U to the uuid of the entity found by[:block/uuid U], which is U, so every lookup ref is rewritten to itself.delete-blocks/build-retracted-tx: the unused 1-arity of this private fn.outliner.tree/blocks->vec-tree: the number and string root-id branches. Both callers pass a block uuid or nil.page/create: the convert-to-class branch. Withclass?the existing page is looked up among pages tagged Tag (or is a journal), so it is never a non-class internal page.build-property-value-tx-data:multiple-values-empty?. The block is an entity in every caller, and an entity's cardinality-many value is a set, never sequential.apply-history-action!: the:unsupported-history-actionbranch after(seq ops').ops'falls back to[[:transact ...]], so it is never empty.logseq.db:*debounce-fnandregister-debounce-fn!. The atom is read only inside a(comment ...)form.Found by mutation testing (each was a surviving mutant: removing or changing it changed nothing any test could see), then checked against every caller on master.
fix(outliner): a built-in node refuses task properties with a message
Found by a local key fuzzer (it opened the built-in Page class through the search dialog and typed
DONE): setting a status, scheduled date or deadline also tags the node #Task when no class provides the property, but a built-in node keeps its one built-in tag, so validation rejected the write (should only have one tag for a built-in entity) and the user saw only the generic "DB write failed with invalid data".disallow-task-properties-on-built-in-nodes(validate.cljs) refuses those three properties on built-in nodes with a notification, "Built-in nodes can't be tasks.", fromset-block-property!andbatch-set-property!'s validation, next to the existing private built-in check; ordinary pages still become tasks.New test
logseq.outliner.property-test/task-properties-on-built-in-nodes: a status on the Page class through both setters is refused with the notification (before the change both failed with "DB write failed with invalid data") and leaves the class untouched; a plain page still becomes a task. The outliner library's suite passes.fix(db): a deleted block no longer comes back from its batch
What happened. A key fuzzer sent one
apply-outliner-opscall that moved three blocks into block X as its children, deleted X, then saved X (a Backspace merge whose previous block was X itself). The whole write failed with "DB write failed with invalid data": the three moved blocks were deleted with X, then came back as stubs holding only:block/order(with blocks moved in from beside X, also:block/parent), which fail validation.Cause.
apply-ops!runs the batch on a temporary conn and replays its datoms in onetransact!. With:outliner-op :delete-blocks, which the editor sets on a Backspace merge,expand-delete-blocks-tx(deps/db/src/logseq/db/common/delete_blocks.cljs) randistinctover that tx-data. DataScript datoms are equal when their e, a and v are equal, whateveraddedis. So when the move added a block's order and parent and the delete then retracted those same values,distinctdropped the retract as a duplicate of the add and kept the add.Fix.
expand-delete-blocks-txkeeps the tx-data as it is and dedupes only the subtree retracts it appends. After the batch, X and its whole subtree, including the moved blocks, are gone and the transaction is valid.Tests.
frontend.worker.pipeline-test/move-into-block-then-delete-it-does-not-resurrect-moved-blocks-testruns the fuzzer's batch throughapply-ops!with the worker pipeline and{:outliner-op :delete-blocks}. It runs twice, once with the moved blocks as X's children and once with them as X's siblings. It checks that X and the moved blocks leave no datoms behind, that the block after X survives, and thatvalidate-dbfinds no errors. Before the fix it fails with the same "invalid dispatch value" stubs the fuzzer reported.fix(worker): property reads return nil before the graph is open
Right after a reload the renderer can call
:thread-api/get-class-objects,:thread-api/get-property-valuesand:thread-api/get-bidirectional-propertiesbefore the worker has opened the graph. They deref the graph's nil conn and throwNo protocol method IDeref.-deref defined for type null(found by a local key fuzzer that reloads mid-session). They now use the samewhen-leton the conn as the neighbouring read handlers infrontend.worker.handler.propertyand return nil until the graph is open. The same change for the read handlers in other files is #13862;property.cljsis already in this PR, so its part is here.New test
src/test/frontend/worker/handler/property_graph_not_open_test.cljsproperty-read-thread-apis-return-nil-before-graph-opens-test: calls the three for a repo with no conn; all three throw on master and return nil with the change.fix(outliner): text for a number property is refused with a message
Setting a
:numberproperty to text that isn't a number throughbatch-set-property!(the value picker of the add-property dialog) went throughconvert-ref-property-value, whereparse-doublereturned nil, and the write failed asProperty value must be not nil: a raw worker error, nothing shown to the user. It now usesfail-parse-double, asconvert-property-input-stringalready does, so the user gets "Can't convert "x" to a number." (:property.validation/cant-convert-to-number) and nothing is written. Found by a local key fuzzer that typed#statusinto a number property's value picker.New test
batch-set-property-refuses-a-value-it-cant-convert(deps/outliner/test/logseq/outliner/property_test.cljs): the write is refused with a notification and the block keeps no value; on master it fails with the raw error.fix(worker): reordering a block's properties answers the renderer
:thread-api/reorder-display-property(dragging a property to a new place in a block's property list) returned the result ofldb/transact!, a tx report, which the worker can't send back to the renderer: the call failed withCannot write $datascript$db$TxReport$$although the reorder was saved. It returns nil now. No other thread api returns a transact call's result. Found by a local key fuzzer that drags at random.New test
src/test/frontend/worker/handler/property_reorder_test.cljsreorder-display-property-returns-a-value-the-renderer-can-read-test: the reorder is saved and the result can be written as transit; on master it fails with the tx report.Master's #13043 (8ab397f, "return a serializable property reorder result") makes the same change; on the rebase onto it this commit keeps master's code and only adds the test, which passes there.
A tag converted to a page no longer stops the graph from opening (fixes #13877)
Converting a tag to a page left the tags that extend it pointing at the page. Once the page was recycled and the 30-day recycle GC removed it, those tags had no parent, the GC write failed validation (
:logseq.property.class/extendsmissing), and because the GC runs while the graph opens, the graph never opened again.logseq.db.frontend.class/detach-child-classes-tx: tags extending a parent that stops being a tag, or is retracted, drop that parent; a tag left with no parent extends Root, the same thing deleting a tag does.convert-tag-to-pageuses it, so new conversions leave no stale parent.maybe-run-recycle-gc!logs a GC failure instead of throwing it into the graph open.Tests:
logseq.outliner.recycle-test/gc-recycled-page-converted-from-parent-tag-keeps-graph-valid(a graph in the state earlier versions left: GC succeeds, the child extends Root, the graph validates),frontend.worker.db-core-test/convert-tag-to-page-moves-its-child-tags-to-root,frontend.worker.handler.transaction-test/a-failing-recycle-gc-does-not-stop-the-graph-from-opening. Each fails without its change.Fixes logseq/db-test#1421: a graph that will not open because the startup recycle GC deletes a page a tag still extends, leaving the tag with an invalid
extends. The GC and permanent delete detach child classes throughdb-class/detach-child-classes-tx(above). A node-ops fuzzer (random outliner ops including recycle-delete, permanent delete and the GC run as at graph open, checking that the graph validates after each) reproduces the issue's plain-page case on master at seeds 4018, 4110, 4307 and 4320; on this branch none of them fail that way. Pinned bygc-recycled-page-converted-from-parent-tag-keeps-graph-valid.Rebase onto master 29fd2ed (Nov 11)
replays-tx-datoms?inundo_redo.cljs); every other local transaction still replays its datoms. The PR's mark-graph-synced! workaround inredo-create-page-restores-recycled-page-testis gone, and the pipeline replay test expects the page recycled after the undo.undo_redo_test.cljs(master keeps appending there) intofrontend.worker.undo-redo-local-replay-test.deps/outliner/.../validate.cljskeeps master's recycled-page skip and this PR's Library-as-top-level argument;deps/outliner/.../property.cljskeeps master'signore-root-extends-add?guard and dropsold-valuewithmultiple-values-empty?.A page linked by a uuid lookup in a save is not retracted as orphaned
What the user sees. Saving a block whose new title links a page by uuid (
Updated Link [[<page uuid>]], as master's input path stores links) failed with "Nothing found for entity id" when that page had no other refs: the save retracted the page it links.Cause.
remove-orphaned-page-refs!reads the new refs by:block/nameor:db/idonly, so a[:block/uuid id]lookup ref counted as dropped. Master kept such a page because every page's:block/propertieshold its tags; this PR's orphan check looks past the tags, so the page became an orphan of its own save. Caught by master'scli-page-block-and-missing-uuid-linksin the nightly build.Change. A lookup ref (
[:block/uuid id], or a map with only:block/uuid) has its page name read from the db before the old and new refs are compared.Test. master's
frontend.worker.pipeline-cli-refs-test/cli-page-block-and-missing-uuid-linkserrors on this branch without the change and passes with it;deps/outliner173 tests pass.