Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions migrations/V144__map_version_folder_name.sql
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Align column lengths to prevent derived filename overflow.

folder_name is allowed up to 200 chars, but generated filename is varchar(200) and adds 9 fixed chars (maps/ + .zip). Any folder_name longer than 191 can fail writes (or truncate, depending on SQL mode).

Suggested fix
-ALTER TABLE map_version ADD COLUMN folder_name varchar(200) NULL AFTER filename;
+ALTER TABLE map_version ADD COLUMN folder_name varchar(191) NULL AFTER filename;
...
 ALTER TABLE map_version
-  MODIFY folder_name varchar(200) NOT NULL,
+  MODIFY folder_name varchar(191) NOT NULL,
   ADD UNIQUE KEY folder_name (folder_name);

Also applies to: 22-23, 30-30

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@migrations/V144__map_version_folder_name.sql` at line 13, The folder_name
column is set to varchar(200) but the generated filename concatenates it with
fixed characters (maps/ prefix and .zip suffix totaling 9 characters), which can
exceed the filename column's varchar(200) limit if folder_name exceeds 191
characters. Change the folder_name column definition in the ALTER TABLE
map_version statement from varchar(200) to varchar(191) to prevent potential
overflow. Also apply the same reduction to the folder_name column definitions at
lines 22-23 and line 30 in this migration file.


-- 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;
Loading