Skip to content

Commit 22bfa8f

Browse files
committed
Only update the changed fields when updating a messge from the backend
1 parent 97e7208 commit 22bfa8f

File tree

1 file changed

+9
-2
lines changed
  • python/jupyterlab-chat/jupyterlab_chat

1 file changed

+9
-2
lines changed

python/jupyterlab-chat/jupyterlab_chat/ychat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,19 @@ def update_message(self, update: Message, append: bool = False):
165165
index = self._indexes_by_id[update.id]
166166
message = self._ymessages[index]
167167
except (KeyError, IndexError) as e:
168-
print(e)
168+
self.log.error(e)
169169
return
170170
update_dict = asdict(update)
171171
if (update.body and append):
172172
update_dict["body"] = message.get("body") + update.body
173-
message.update(update_dict)
173+
174+
# Only update the changed values.
175+
for key in update_dict:
176+
if key in message:
177+
if message[key] != update_dict[key]:
178+
message.update({ key: update_dict[key] })
179+
elif update_dict[key] is not None:
180+
message.update({ key: update_dict[key] })
174181

175182
def get_attachments(self) -> dict[str, Union[FileAttachment, NotebookAttachment]]:
176183
"""

0 commit comments

Comments
 (0)