Repository navigation
improvement(db): name chat uploads in one indexed read and index workspace payer lookups - #9208
Merged
waleedlatif1 merged 2 commits intoOct 18, 2026
Merged
Conversation
…space payer lookups - trackChatUpload reads the chat's taken display names once (unique-index predicate, LIKE-escaped suffix pattern, excluding the re-linked row) and writes the first free name, instead of probing each candidate with a write that a unique violation rolls back - add workspace_billed_account_user_id_idx (concurrent) for payer lookups and the user FK's delete check
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
[High impact] The PR appears safe to merge; no actionable defects were found. SummaryThe PR replaces repeated name-conflict writes with one lookup before each chat upload write.
No actionable issues were found. Runtime tests were not run during this review. Reviews (1) · Last reviewed commit: "improvement(db): name chat uploads in on..." · Reviewed by Greptile |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
trackChatUploadprobed display names by writing: each candidate (image.png,image (2).png, …) was its own transaction + project lock + UPDATE/INSERT, and a taken name surfaced as a 23505 onworkspace_files_chat_display_name_unique. A message with N same-named attachments cost 1+2+…+N writes (20 attachments → 210 writes, ~60ms per failed attempt, multi-second chat POSTs)<stem> (%)<ext>, LIKE-escaped withescapeLikePattern) using the unique index's own predicate (context = 'mothership', chat set, soft-deleted rows included), excludes the row being re-linked, and writes the first freesuffixedName. The 23505 retry stays for races, and a lost candidate is never retriedwithCopySuffixnow shares its stem/extension split with the LIKE pattern so the two cannot driftworkspace_billed_account_user_id_idx(plain btree,CREATE INDEX CONCURRENTLYwith the 0429 invalid-index recovery).workspace.billed_account_user_idhad no index, so the GET /api/billing upgrade-target lookup and account deletion seq-scannedworkspace, and so did theuserFK's (no action) delete check. A plain index serves all of these: the equality lookup, theowner_id OR billed_account_user_iddeletion queries (BitmapOr withworkspace_owner_id_idx), and the FK check. A user has few workspaces, so a composite or partial index buys nothingType of Change
Testing
file-names.integration.ts(real Postgres), new cases: 20 same-named attachments (10 re-links + 10 inserts) in one chat, a re-link that keeps its name while a soft-deleted sibling holdsimage.png, and names with%,_,\, parentheses, no extension, a leading dot, and multiple dots. A trigger counts every display-name write through a sequence, which a rollback does not undoimage (3).pngpushandINTEGRATION_DB_PROVISION=migrate(applies 0435)workspace_files_chat_display_name_unique, Index Cond onchat_id. Payer lookup before the index: Seq Scan onworkspacetrack-chat-upload.test.ts,file-manager.test.ts;bun run lint;check:test-patterns;check:comment-hygiene;check:migrations origin/staging;drizzle-kit generatereports no changesChecklist
test-auditauthoring gate)