mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-05 02:41:34 +00:00
fix: typing quickly in a note can leave the saved note missing the last characters
When edits to a note arrived a few milliseconds apart, an older edit could finish its server-side checks after a newer one and replace its pending save. The saved note then stayed a few characters behind the editor, most often on a shared note edited by someone other than the owner. The last edit made is now always the one that gets saved. Fixes #31585
This commit is contained in:
parent
176d31d1db
commit
054a831a21
1 changed files with 14 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import logging
|
|||
import random
|
||||
import sys
|
||||
import time
|
||||
import weakref
|
||||
from contextlib import suppress
|
||||
from typing import Any
|
||||
|
||||
|
|
@ -203,6 +204,7 @@ REDIS_EVENT_CHANNEL = f'{REDIS_KEY_PREFIX}:direct_completion'
|
|||
|
||||
EVENT_QUEUES: dict[str, asyncio.Queue] = {}
|
||||
EVENT_PUBLISH_LOCK = asyncio.Lock()
|
||||
DOCUMENT_UPDATE_LOCKS: weakref.WeakValueDictionary[str, asyncio.Lock] = weakref.WeakValueDictionary()
|
||||
|
||||
|
||||
def get_session_pool_batches():
|
||||
|
|
@ -825,6 +827,18 @@ async def yjs_document_state(sid, data):
|
|||
|
||||
@sio.on('ydoc:document:update')
|
||||
async def yjs_document_update(sid, data):
|
||||
try:
|
||||
document_id = normalize_document_id(data['document_id'])
|
||||
except Exception as e:
|
||||
log.error('Error in yjs_document_update: %s', e)
|
||||
return
|
||||
|
||||
# Keep per-document updates in arrival order
|
||||
async with DOCUMENT_UPDATE_LOCKS.setdefault(document_id, asyncio.Lock()):
|
||||
await handle_yjs_document_update(sid, data)
|
||||
|
||||
|
||||
async def handle_yjs_document_update(sid, data):
|
||||
"""Handle Yjs document updates"""
|
||||
try:
|
||||
document_id = data['document_id']
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue