-
-
Notifications
You must be signed in to change notification settings - Fork 20
Add map_version.folder_name column, derive filename #332
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| -- Make the map folder name a real, indexable column. | ||
| -- | ||
| -- Previously only `filename` (e.g. `maps/scmp_001.v0001.zip`) was stored, and the | ||
| -- API derived the folder name from it in-memory in a @PostLoad enricher. That made | ||
| -- `versions.folderName == X` filters impossible to push down to SQL, forcing a full | ||
| -- table scan + in-memory enrichment on every map lookup (~5s per request). | ||
| -- | ||
| -- `folder_name` (e.g. `scmp_001.v0001`) becomes the source of truth. `filename` is | ||
| -- kept as a VIRTUAL generated column so external readers (faf-server, replay server) | ||
| -- and existing API clients continue to see the identical `maps/<folder>.zip` value. | ||
|
|
||
| -- 1. add the new source-of-truth column | ||
| ALTER TABLE map_version ADD COLUMN folder_name varchar(200) NULL AFTER filename; | ||
|
|
||
| -- 2. backfill, prefix/suffix-agnostic (mirrors the old Java extraction: | ||
| -- part after the last '/', up to '.zip') | ||
| UPDATE map_version | ||
| SET folder_name = SUBSTRING_INDEX(SUBSTRING_INDEX(filename, '/', -1), '.zip', 1); | ||
|
|
||
| -- 3. enforce constraints on the new column | ||
| ALTER TABLE map_version | ||
| MODIFY folder_name varchar(200) NOT NULL, | ||
| ADD UNIQUE KEY folder_name (folder_name); | ||
|
|
||
| -- 4. drop the old real filename column (drops its now-redundant UNIQUE key) and | ||
| -- re-add it as a VIRTUAL generated column (no storage, no index needed). Its | ||
| -- uniqueness is implied by the UNIQUE folder_name it is derived from. | ||
| ALTER TABLE map_version DROP COLUMN filename; | ||
| ALTER TABLE map_version | ||
| ADD COLUMN filename varchar(200) AS (CONCAT('maps/', folder_name, '.zip')) VIRTUAL; | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align column lengths to prevent derived
filenameoverflow.folder_nameis allowed up to 200 chars, but generatedfilenameisvarchar(200)and adds 9 fixed chars (maps/+.zip). Anyfolder_namelonger than 191 can fail writes (or truncate, depending on SQL mode).Suggested fix
Also applies to: 22-23, 30-30
🤖 Prompt for AI Agents