Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove now-unreachable chat history keyed on primary email #2695

Merged
merged 1 commit into from
Jan 12, 2024

Conversation

sqs
Copy link
Member

@sqs sqs commented Jan 12, 2024

In #2665 we migrated the chat history key to use the user's username instead of their email address. This means that the storage would retain the chat history under the old key indefinitely.

Large storage data slows down extension host activation and every set operation. My storage was 1.8MB, which was causing warnings from VS Code like this:

[mainThreadStorage] large extension state detected (extensionId: sourcegraph.cody-ai, global: true): 916.8603515625kb. Consider to use 'storageUri' or 'globalStorageUri' to store this data on disk instead.

Each Memento#set call was taking ~37ms (with 1.8MB of data). With ~1kb of data, each set call takes ~1-3ms.

Of course, the data will accumulate as the user uses Cody more, but at least we can manage the data now without some of it being "orphaned".

Test plan:

Confirmed that this removes the old data:

  1. Added a console.log to ensure that the code had the right before/after values.
  2. Confirmed the storage DB on disk had the keys before and after the migration did not have them, with sqlite3 ~/.config/Code/User/globalStorage/state.vscdb "select value from itemtable where key='sourcegraph.cody-ai';" | jq '."cody-local-chatHistory-v2" | keys'.
  3. Confirmed the length of the key's value went down (from 1.8MB to 672 bytes, as expected).

In #2665 we migrated the chat history key to use the user's username instead of their email address. This means that the storage would retain the chat history under the old key indefinitely.

Large storage data slows down extension host activation and every `set` operation. My storage was 1.8MB, which was causing warnings from VS Code like this:

```
[mainThreadStorage] large extension state detected (extensionId: sourcegraph.cody-ai, global: true): 916.8603515625kb. Consider to use 'storageUri' or 'globalStorageUri' to store this data on disk instead.
```

Each `Memento#set` call was taking ~37ms (with 1.8MB of data). With ~1kb of data, each set call takes ~1-3ms.

Of course, the data will accumulate as the user uses Cody more, but at least we can manage the data now without some of it being "orphaned".

Test plan:

Confirmed that this removes the old data:

1. Added a console.log to ensure that the code had the right before/after values.
2. Confirmed the storage DB on disk had the keys before and after the migration did not have them, with `sqlite3 ~/.config/Code/User/globalStorage/state.vscdb "select value from itemtable where key='sourcegraph.cody-ai';" | jq '."cody-local-chatHistory-v2" | keys'`.
3. Confirmed the length of the key's value went down (from 1.8MB to 672 bytes, as expected).
@sqs sqs requested a review from a team January 12, 2024 07:52
Copy link
Contributor

@dominiccooney dominiccooney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@sqs sqs merged commit 9408335 into main Jan 12, 2024
16 checks passed
@sqs sqs deleted the sqs/delete-orphaned-storage-data branch January 12, 2024 08:05
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice cleanup. I'm working on supporting persistent chat history for JetBrains and it wasn't obvious to me when inspecting the raw storage data why some entries had an email and some had a username.

sqs added a commit that referenced this pull request Mar 5, 2024
The migrations in #2473, #2695, and #2665 have been in the code for one major release and more than a month. We can remove them to simplify the code now.

Also remove other unused code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants