Repository navigation
perf(sync): cheaper checksum; undo and no sync rows on local graphs - #13545
yuxi-liu-wired wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| (if local-graph? | ||
| (record-local-graph-undo! repo tx-report) | ||
| (do | ||
| (persist-local-tx! repo tx-report normalized reversed-datoms) |
There was a problem hiding this comment.
🔴 Local edits never reach matched remote graph
When start! matches an unmarked local graph by name, enqueue-local-tx-aux records its edits without pending rows. The sync client uploads pending rows, so those edits never reach the remote graph.
Learn more
A local graph can acquire a sync connection without first setting its graph-remote flag. <resolve-start-graph-id finds a remote graph with the same name, and start! connects to it without marking the local graph remote or uploading a snapshot. New edits then take the no-row branch, while handle-hello! flushes only pending transactions. The remote graph never receives those edits; a subsequent pull can replace conflicting local state.
Example: A local graph named Notes has no remote flag, but the account already contains a remote Notes. After sync starts, editing a block locally writes no pending transaction. Connecting and flushing leaves the remote block unchanged.
Recommended fix: Reconcile graph identity before selecting the no-row path. Either prevent start! from attaching an unmarked graph to an existing remote graph, or make that attachment explicitly set the remote flag and reconcile the graph contents before accepting further edits.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (let [normalized (normalize-tx-data db-after db-before tx-data) | ||
| reversed-datoms (reverse-tx-data db-before db-after tx-data)] | ||
| local-graph? (worker-undo-redo/local-graph? db-after) | ||
| reversed-datoms (when-not local-graph? | ||
| (reverse-tx-data db-before db-after tx-data))] |
There was a problem hiding this comment.
🟡 Local edits still normalize discarded sync data
On a local graph, enqueue-local-tx-aux normalizes every transaction before taking its no-row branch. The normalized data is discarded, so large local edits still pay the sync preparation cost.
Learn more
normalize-tx-data filters and normalizes the transaction's datoms for upload. A local graph writes no client-op row, but this normalization happens before its branch is selected. For a large insert or delete, the worker still processes the entire transaction for an upload payload that is never used.
Example: A paste changes thousands of blocks on a graph without sync. The worker builds normalized operations for the full paste and then only records the original report's datoms for undo.
Recommended fix: Determine whether the graph is local before invoking normalize-tx-data. Only normalize transactions that will be persisted, unless another consumer actually needs the normalized result on local graphs.
Was this helpful? React with 👍 or 👎 to provide feedback.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
57728bf to
1282469
Compare
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
recompute-checksum-matches-reference-test compares recompute-checksum with a reference written from the definition, apart from the production code paths: for each :block/uuid datom whose entity is eligible, the entity's [uuid attr value] tuples, parent and page as their uuids, each digested as FNV-1a and djb2 and summed mod 2^32. The graphs: edge cases (tag-only pages, built-in true and false, a parent or page without a uuid, an entity with a uuid and nothing else), datoms that bypass cardinality and uniqueness (2 titles, 2 uuids, 2 parents with equal uuids, a shared uuid), the sample graph, 2 fixture payloads, and 29 generated graphs, e2ee on and off. The test also pins the value on 1 fixed graph.
The test's datoms carried tx 200, below datascript's tx0 (536870912). Such a datom is missed by (d/datoms db :eavt 3), by (d/datoms db :eavt 3 :block/uuid) and by d/entity, and returned by a walk of the whole :eavt index or of (d/datoms db :avet :block/uuid). The test passed only while the recompute and the incremental update read the uuid the same way. Use the next tx id.
A full recompute checked eligibility with 5 d/datoms lookups per entity, then read the entity's uuid and its datoms with 2 more. Read the entity's :eavt datoms once and answer the eligibility check and the checksum tuples from them. Parent and page uuids are still looked up per tuple.
A full recompute looked up the uuid of every block's parent and page, 2 index seeks per block. Fill an eid to uuid map from 1 walk of the :block/uuid index first and read them from it.
The recompute walked the :block/uuid index and sought each entity's :eavt datoms, then built a tuple set per entity and a [fnv djb] vector per tuple and per digest step. An entity's datoms are adjacent in :eavt, so walk the whole index once, read each entity's eligibility and checksum datoms as the walk passes them, and fold each tuple's digest into 2 running sums, with the entity uuid prefix folded once per entity. An entity still counts once per :block/uuid datom, and an entity with a repeated attribute still goes through the tuple set, which dedupes.
After every graph commit the checksum and the tx it covers were 2 sqlite autocommits on the client-ops database, each a synced write. Write both in 1 transaction.
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.
After every local transaction the db listener writes a client-op row with the change (1 synced sqlite commit per edit), on every graph. On a graph that does not sync (:logseq.kv/graph-remote? not true) the only reader of that row was undo, which read the entry's semantic ops back from it. Undo there now replays the entry's own tx datoms, and the first upload sends a snapshot of the graph and marks the rows done without sending them, so nothing reads the row. On such a graph a local transaction now gets its undo entry and no row: no normalized and reversed datoms, no semantic ops, no upsert, no pending count. On a remote graph nothing changes. The upload's transaction that makes a graph remote ends the undo history: its entries were recorded without rows, and undo on a synced graph takes an entry's ops from its row. Rows written before this change stay as they are. db_sync_test's graphs are now marked remote by with-datascript-conns, as the namespace tests sync paths; the new local-graph tests opt out. Its cleanup no longer resets conns and history that a later async test has installed.
The no-sync-record change marks every graph of the sync tests synced unless it asks to stay local. The checksum tests of graphs that do not sync now ask for a local graph. The reopen test's reopened graph is marked synced already through its storage, so it asks to stay local: a second mark would be a transaction past the covered one.
logseq#13526's 2 tests check the inverse op of a one-to-many property change. With the datom replay, undo on a local graph uses no inverse op, so the tests run on a graph marked synced, where undo still replays the ops.
A graph counted as local unless it had :logseq.kv/graph-remote?, but start! can attach sync to a graph without the flag when a remote graph has its name, and a graph downloaded before 4ce4aed has the remote id and no flag. Their edits got no pending rows, so the client uploaded none of them. local-graph? now also reads the client-op store's remote graph id. On a graph without sync the listener no longer normalizes and reverses the tx for an upload it never makes.
1282469 to
548b46f
Compare
|
Combined with the other PRs that change the same files into #13786. |
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.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.