Repository navigation
fix(undo): replay the tx datoms on local graphs - #13466
yuxi-liu-wired wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🔍 Devin Review: 2 flags
Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
|
One question on Otherwise this looks solid: atomic replay, op pushed back with |
a61ab13 to
b5d4b35
Compare
b5d4b35 to
c4785de
Compare
|
Keeping the replay's meta separate is right, for this reason. The replay transacts recorded datoms, not ops, so its meta carries what describes the change to sync and to listeners: I also rebased the branch on master: it carried #13462's pre-merge commit. The conflicts were in tests only. |
Undo replayed an inverse op built from the change's label, so it lost whatever the change did beyond its label: the values of a deleted property on blocks, the tags of a deleted tag's nodes, the references rewritten to plain text, a child tag's parent. On a graph that does not sync (no :logseq.kv/graph-remote?), nothing lands between a change and its undo, so the exact undo is the change's own tx datoms, flipped and last first. An undo entry on a local graph now keeps the tx report's datoms as [e a v added], in order, with the datoms the worker pipeline added. Undo transacts them flipped and last first, redo as recorded, in one transaction marked :undo-redo/replay-tx-datoms?: the pipeline derives nothing more for it, and ldb/transact! neither expands deletes nor dedupes the datoms. The entry pushed on the opposite stack keeps the replay's own datoms, whose revision stamps are new; a :block/tx-id stamp is retracted whatever its value, since an undo of a later change can restamp an entity. A replay that throws changes nothing; the undo is refused and the history kept. Synced graphs, and entries recorded before a graph synced, keep the semantic ops. Tests that model a synced graph set the flag.
c4785de to
55d4ba8
Compare
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.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.Allow edits from maintainers.