Skip to content

Category imports time out on production: every file-name lookup reads the whole entries table #650

Open

Description

@lgelauff

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

Options

  1. Restore the missing indexes (non-unique for now, because of the duplicates): a migration on entries.
  2. 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.

Activity

  1. lgelauff commented on Oct 5, 2026

    @lgelauff
    CollaboratorAuthor

    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;
    ALTER TABLE 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.

  2. added a commit that references this issue on Oct 10, 2026
  3. lgelauff commented on Oct 10, 2026

    @lgelauff
    CollaboratorAuthor

    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:

    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions