Skip to content

Conversation

@drizco
Copy link
Contributor

@drizco drizco commented Jan 7, 2026

this adds the id column in aichat_events table to the indexes used in the chat history query to help with ordering the chats. we were getting a mysql error saying the sort memory ran out, and while the actual issue is with the hidden context being way too large, it made sense to add these indexes to optimize sorting chat history in the future. we might also want to extract just the json values we need rather than sending hidden context over the wire, but that will happen in follow up work.

Links

Testing story

Deployment strategy

Follow-up work

  • remove the indexes that don't have id
  • select just the values desired in the chat_history query, excluding hiddenContext

Privacy

Security

Caching

PR Creation Checklist:

  • Tests provide adequate coverage
  • Privacy impacts have been documented
  • Security impacts have been documented
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Follow-up work items (including potential tech debt) are tracked and linked

@drizco drizco marked this pull request as ready for review January 7, 2026 21:47
Copy link
Contributor

@Erin007 Erin007 left a comment

Choose a reason for hiding this comment

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

Code changes look good! I'm pretty sure the table is small enough (comparatively) that is should be completely fine, but wondering if there's a risk of the table locking and causing any issue when the migration hits production?

@drizco
Copy link
Contributor Author

drizco commented Jan 8, 2026

Code changes look good! I'm pretty sure the table is small enough (comparatively) that is should be completely fine, but wondering if there's a risk of the table locking and causing any issue when the migration hits production?

should be fine, the indexes can be added in place without locking the table. it's a little slower but worth it! 😅

edit: I guess it doesn't guarantee not to lock, but it should be less disruptive and allows concurrent reads/writes

@drizco drizco merged commit 988c676 into staging Jan 8, 2026
6 checks passed
@drizco drizco deleted the ryan/aichat/feat/add-indexes-with-id-for-chat-history branch January 8, 2026 16:18
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.

2 participants