You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Category imports time out on production: every file-name lookup reads the whole entries table #650
Since the deploy of 2026-10-04, category imports of a few thousand files on production fail after 30 s (gunicorn worker timeout, SystemExit from handle_abort), for example Images from Wiki Loves Monuments 2026 in Italy - historic villas and palaces (6,036 files) and Images from Wiki Loves Monuments 2026 in Russia (15,678 files, five attempts). On montage-beta the Russia import gets through the lookups in about 8 s.
Cause
Production's entries table (about 2.03M rows) has no index on name:
SHOW INDEX FROM entries: only PRIMARY, ix_entries_upload_date and ix_entries_file_id. The model also declares ix_entries_name (unique), ix_entries_upload_user_id and ix_entries_upload_user_text; those are missing. All other tables have the indexes the model declares.
EXPLAIN SELECT id FROM entries WHERE name IN (...): type ALL, rows 2,033,473.
During an import, a processlist trace showed one connection running SELECT entries.* FROM entries WHERE entries.name IN (...) back to back for the full 30 s, about 1 s each. add_entries() runs that lookup per chunk of 200 names, and again after the insert to read back the ids: about 60 lookups for 6k files, 160 for 16k.
Consequences seen in the data
Exact duplicate rows. 43,993 file names occur exactly twice in entries (identical bytes), almost all created between 2025-10-01 and 2025-11 by WLM 2025 imports (Russia, Italy national and regional, later the international jury rounds). Both copies are in use by different rounds. Without the unique index, two overlapping imports of the same files (each taking minutes) could both insert a file. Probably related: Odd behavior during file import #324 (imports taking 2-3 minutes, October 2025) and Two simultaneous imports into one round add every file twice #635.
The index was probably lost when the tables were recreated on 2025-07-01: the first duplicates appear in rounds created on 2025-10-01.
Options
Restore the missing indexes (non-unique for now, because of the duplicates): a migration on entries.
Make the lookup itself cheaper without a new index, by also filtering on upload_date, which is indexed: see #DATESLICE.
Later, separately: merge the duplicate rows, then decide on a unique key (name in a binary collation, or file_id; only 35,650 of 2.03M rows have a file_id so far), see #645.
Written with Claude (Claude Code) on behalf of @lgelauff.
Tested on montage-dev with production's code and data: master cb50599 (what production runs) on the shuffled copy of production from #652, whose entries table has the same indexes as production (no index on name). Imports run in the request, as on production.
Import
Files
Without ix_entries_name
With ix_entries_name
Category of the Italy historic villas campaign
~6,000
request killed after 31 s, nothing saved
6,034 files in 3 s
Category of the Russia campaign
15,676
≤ 13 s
Images from Wiki Loves Monuments 2026 in Italy
26,428 (all new)
18.2 s
The index was added with
SET SESSION lock_wait_timeout =10;
ALTERTABLE entries ADD INDEX IF NOT EXISTS ix_entries_name (name), ALGORITHM=INPLACE, LOCK=NONE;
which took seconds on the 2M-row table, without blocking reads or writes.
Conclusion: restoring the non-unique ix_entries_name on production is enough to unblock the imports that time out now (the Italy villas and Russia campaigns), without a code change or deploy.
I do see problems with the fact that files get renamed, encoding is not perfect, and other potential problems with using a name as a lookup.
The timeouts are gone for current campaigns. Since #654 (on production since 2026-10-05), imports into campaigns that open on or after 2026-06-01 look existing entries up by file_id (indexed), not by name. The WLM 2026 imports after that went through, for example 15,667 files for Russia and 6,071 for Italy historic. The timeouts of 2026-10-04 (at least ten import requests killed after 30 s) all fell before that deploy.
The index on entries.name is still missing on production (checked today). The non-unique index tested on montage-dev (see the comment above: seconds to add, no locking) would also speed up the name lookups that remain, such as files imported before 2026-05-31 that have no file_id yet. That is no longer urgent, but it is cheap.
Rows without a file_id: a file imported before 2026-05-31 gets a second entries row when it is imported again, because it cannot be found by file_id. The backfill script for Backfill file_id for entries imported before #505 migration #513 fills file_id for those rows; it is ready for a first run on montage-dev.
Side effect of 2026-10-04, now fixed: each timed-out import left an empty round behind, which blocked creating a new one. Coordinators cancelled them. One campaign still has an empty paused round. #656 saves a first round and its files together, so this cannot happen again.
Activity
lgelauff commentedon Oct 5, 2026
Tested on montage-dev with production's code and data: master
cb50599(what production runs) on the shuffled copy of production from #652, whoseentriestable has the same indexes as production (no index onname). Imports run in the request, as on production.ix_entries_nameix_entries_nameThe index was added with
which took seconds on the 2M-row table, without blocking reads or writes.
Conclusion: restoring the non-unique
ix_entries_nameon production is enough to unblock the imports that time out now (the Italy villas and Russia campaigns), without a code change or deploy.I do see problems with the fact that files get renamed, encoding is not perfect, and other potential problems with using a name as a lookup.
fix(#510): a name taken by another file in Montage is caught by the c…
lgelauff commentedon Oct 10, 2026
Update (2026-10-10)
The timeouts are gone for current campaigns. Since #654 (on production since 2026-10-05), imports into campaigns that open on or after 2026-06-01 look existing entries up by
file_id(indexed), not by name. The WLM 2026 imports after that went through, for example 15,667 files for Russia and 6,071 for Italy historic. The timeouts of 2026-10-04 (at least ten import requests killed after 30 s) all fell before that deploy.What is still open:
file_id.entries.nameis still missing on production (checked today). The non-unique index tested on montage-dev (see the comment above: seconds to add, no locking) would also speed up the name lookups that remain, such as files imported before 2026-05-31 that have nofile_idyet. That is no longer urgent, but it is cheap.file_id: a file imported before 2026-05-31 gets a secondentriesrow when it is imported again, because it cannot be found byfile_id. The backfill script for Backfill file_id for entries imported before #505 migration #513 fillsfile_idfor those rows; it is ready for a first run on montage-dev.Side effect of 2026-10-04, now fixed: each timed-out import left an empty round behind, which blocked creating a new one. Coordinators cancelled them. One campaign still has an empty paused round. #656 saves a first round and its files together, so this cannot happen again.
Drafted by Claude (Claude Code)