mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
perf: avoid double stringification in ChatRecordingService
This commit is contained in:
@@ -461,9 +461,18 @@ export class ChatRecordingService {
|
|||||||
// when nothing has changed.
|
// when nothing has changed.
|
||||||
const currentContent = JSON.stringify(conversation, null, 2);
|
const currentContent = JSON.stringify(conversation, null, 2);
|
||||||
if (this.cachedLastConvData !== currentContent) {
|
if (this.cachedLastConvData !== currentContent) {
|
||||||
// Only update the timestamp and re-stringify if something actually changed.
|
// To avoid a second full stringification for a large conversation object,
|
||||||
conversation.lastUpdated = new Date().toISOString();
|
// we can replace just the timestamp in the already stringified content.
|
||||||
const finalContent = JSON.stringify(conversation, null, 2);
|
// This is significantly more performant.
|
||||||
|
const newTimestamp = new Date().toISOString();
|
||||||
|
const finalContent = currentContent.replace(
|
||||||
|
`"lastUpdated": "${conversation.lastUpdated}"`,
|
||||||
|
`"lastUpdated": "${newTimestamp}"`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update the in-memory object's timestamp to stay in sync.
|
||||||
|
conversation.lastUpdated = newTimestamp;
|
||||||
|
|
||||||
this.cachedLastConvData = finalContent;
|
this.cachedLastConvData = finalContent;
|
||||||
fs.writeFileSync(this.conversationFile, finalContent);
|
fs.writeFileSync(this.conversationFile, finalContent);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user