fix: keep the pending note save when an update carries no content snapshot (#28669)
stop_item_tasks() ran unconditionally while create_task() only ran when the update carried data, so an update without a content snapshot cancelled the pending save without scheduling a replacement and the edits were never written.
This commit is contained in:
1 parent
bf08835d6f
commit
5735123f50
1 file changed
+10
-5
@@ -803,11 +803,6 @@ async def yjs_document_update(sid, data):
|
|||||||
log.warning(f'User {user.get("id")} does not have write access to note {note_id}. Rejecting update.')
|
log.warning(f'User {user.get("id")} does not have write access to note {note_id}. Rejecting update.')
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
await stop_item_tasks(REDIS, document_id)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
user_id = data.get('user_id', sid)
|
user_id = data.get('user_id', sid)
|
||||||
|
|
||||||
update = data['update'] # List of bytes from frontend
|
update = data['update'] # List of bytes from frontend
|
||||||
@@ -835,6 +830,16 @@ async def yjs_document_update(sid, data):
|
|||||||
await document_save_handler(document_id, data.get('data', {}), user)
|
await document_save_handler(document_id, data.get('data', {}), user)
|
||||||
|
|
||||||
if data.get('data'):
|
if data.get('data'):
|
||||||
|
# Only drop the pending save when a new one takes its place.
|
||||||
|
# Updates without a content snapshot (the resync a client sends
|
||||||
|
# after rejoining a document) would otherwise cancel the pending
|
||||||
|
# save without scheduling a replacement, so the edits made just
|
||||||
|
# before the resync never reach the database.
|
||||||
|
try:
|
||||||
|
await stop_item_tasks(REDIS, document_id)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
await create_task(REDIS, debounced_save(), document_id)
|
await create_task(REDIS, debounced_save(), document_id)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in new issue
Block a user