refac
This commit is contained in:
1 parent
a4738e0459
commit
1c13fedb16
4 files changed
+82
-55
No files matched your search
@@ -1361,15 +1361,8 @@ async def update_chat_by_id(
|
||||
):
|
||||
chat = await Chats.get_chat_by_id_and_user_id(id, user.id, db=db)
|
||||
if chat:
|
||||
updated_chat = {**chat.chat, **form_data.chat}
|
||||
if 'history' in form_data.chat:
|
||||
updated_chat['history'] = Chats.merge_history(
|
||||
chat.chat.get('history'),
|
||||
form_data.chat.get('history'),
|
||||
)
|
||||
|
||||
touch = 'history' in form_data.chat or 'messages' in form_data.chat
|
||||
chat = await Chats.update_chat_by_id(id, updated_chat, db=db, touch=touch)
|
||||
chat = await Chats.update_chat_by_id(id, form_data.chat, db=db, touch=touch)
|
||||
if form_data.variables is not None:
|
||||
chat = (
|
||||
await Chats.update_chat_variables_by_id(
|
||||
@@ -1383,7 +1376,7 @@ async def update_chat_by_id(
|
||||
|
||||
# Reconcile chat_message rows without inferring deletes from missing IDs.
|
||||
# Message deletion has its own endpoint below.
|
||||
messages = (updated_chat.get('history') or {}).get('messages') or {}
|
||||
messages = ((chat.chat or {}).get('history') or {}).get('messages') or {}
|
||||
if messages:
|
||||
await Chats.reconcile_messages_by_chat_id(id, user.id, messages)
|
||||
|
||||
|
||||
@@ -339,11 +339,10 @@ async def get_note_chat_by_id(
|
||||
chat = await Chats.get_internal_chat_by_note_id(note.id, user.id, db=db)
|
||||
if chat:
|
||||
log.info('[note-chat] reusing hidden chat note_id=%s chat_id=%s user_id=%s', note.id, chat.id, user.id)
|
||||
payload = {**(chat.chat or {})}
|
||||
params = {**(payload.get('params') or {})}
|
||||
params = {**((chat.chat or {}).get('params') or {})}
|
||||
changed = False
|
||||
|
||||
if params.pop('note_id', None) is not None:
|
||||
if 'note_id' in params:
|
||||
del params['note_id']
|
||||
changed = True
|
||||
|
||||
system = (
|
||||
@@ -356,12 +355,8 @@ async def get_note_chat_by_id(
|
||||
params['system'] = system
|
||||
changed = True
|
||||
|
||||
if payload.pop('system', None) is not None:
|
||||
changed = True
|
||||
|
||||
payload['params'] = params
|
||||
if changed:
|
||||
updated_chat = await Chats.update_chat_by_id(chat.id, payload, db=db, touch=False)
|
||||
updated_chat = await Chats.update_chat_by_id(chat.id, {'params': params}, db=db, touch=False)
|
||||
if updated_chat:
|
||||
return updated_chat
|
||||
|
||||
@@ -434,11 +429,10 @@ async def get_note_chats_by_id(
|
||||
chats = await Chats.get_internal_chats_by_note_id(note.id, user.id, db=db)
|
||||
normalized_chats = []
|
||||
for chat in chats:
|
||||
payload = {**(chat.chat or {})}
|
||||
params = {**(payload.get('params') or {})}
|
||||
params = {**((chat.chat or {}).get('params') or {})}
|
||||
changed = False
|
||||
|
||||
if params.pop('note_id', None) is not None:
|
||||
if 'note_id' in params:
|
||||
del params['note_id']
|
||||
changed = True
|
||||
|
||||
system = (
|
||||
@@ -451,12 +445,8 @@ async def get_note_chats_by_id(
|
||||
params['system'] = system
|
||||
changed = True
|
||||
|
||||
if payload.pop('system', None) is not None:
|
||||
changed = True
|
||||
|
||||
payload['params'] = params
|
||||
if changed:
|
||||
chat = await Chats.update_chat_by_id(chat.id, payload, db=db, touch=False) or chat
|
||||
chat = await Chats.update_chat_by_id(chat.id, {'params': params}, db=db, touch=False) or chat
|
||||
|
||||
normalized_chats.append(chat)
|
||||
|
||||
|
||||
Reference in new issue
Block a user