* perf: Use FOR NO KEY UPDATE where locked rows are only updated
Rows that other tables reference by foreign key are now locked with
FOR NO KEY UPDATE when the transaction only updates or soft-deletes
them, so concurrent inserts that reference the row are not blocked.
* test: Collaborative save does not wait for foreign key inserts
* fix: Revision and document attribution to the wrong user in collaborative edits
Capture the editing user synchronously with each Yjs update and persist an
ordered, sequenced collaborator set in Redis so that snapshots and revisions
are attributed to the user who actually made the change.
* fix: Do not fail a committed save when the update event cannot be scheduled
* fix: Consume collaborator attribution when a revision is skipped as identical
* refactor: Add zlatestWithSequence to the Redis adapter
* perf: shorten row lock held while persisting collaborative documents
The collaborative updater serialized the Y.js state and converted it to
ProseMirror JSON while holding a FOR UPDATE lock on the document row, and
loaded every column including the deprecated markdown text. Both the lock
wait on the SELECT and the subsequent UPDATE are the dominant source of
statement timeouts in production, and API document updates queue behind
the same lock.
Allows API clients to detect concurrent edits by rejecting the update
with a 409 when the document revision no longer matches. Collaborative
persists now also increment revisionCount so the check is reliable.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Guard against null collaboratorIds when persisting collaborative
updates; the DB column has no default and can be NULL on older rows.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
* chore: Replace lodash with es-toolkit
Migrate all direct lodash imports to es-toolkit/compat for a smaller,
faster, lodash-compatible utility library. Transitive lodash usage from
other packages remains unchanged.
* fix: Restore isPlainObject semantics in CanCan policy
The lodash migration aliased `isObject` to `lodash/isPlainObject` and
the codemod incorrectly mapped the local name to es-toolkit's `isObject`,
which also returns true for arrays and functions. This caused condition
objects in policy definitions to be skipped, breaking authorization
checks across the codebase.
* fix: Restore unicode-aware length counting in validators
es-toolkit/compat's size() returns string.length, while lodash's _.size()
counts unicode code points. Switch to [...value].length to preserve the
previous behavior so multi-byte characters like emoji count as one.
* perf: Move text serialization to task runner
* tsc
* test
* refactor
* fix: Restore previous default of toMarkdown behavior
* Stop writing text to revisions