8000 Create the search index explicitly instead of on Django startup by daoudclarke · Pull Request #562 · mwmbl/mwmbl · GitHub
[go: up one dir, main page]

Skip to content

Create the search index explicitly instead of on Django startup - #562

Merged
daoudclarke merged 2 commits into
mainfrom
explicit-create-index
Oct 30, 2026
Merged

daoudclarke merged 2 commits into
mainfrom
explicit-create-index

Conversation

@daoudclarke
Copy link
Copy Markdown
Contributor

Stacked on #561. Merge that first; this PR will then retarget to main.

What changed

  • ready(): MwmblConfig.ready() no longer creates the search index. It still creates and resizes the external cache, which is disposable and depends on rebuilding at boot.
  • New command: manage.py create_index creates the search index if it's missing and checks the shape of an existing one. make install now runs it through a new make create-index target.
  • Server startup checks: search_setup.py (where the server opens the index) refuses to start if the index is missing, with a message pointing at the command. It also refuses if the index's shape doesn't match NUM_PAGES. That keeps the protection ready() used to give the production index. The shape check is factored out as index_shape_mismatch() and shared with create_index().
  • Crawler: the crawler's main() creates its own index, so volunteers still need no setup step.
  • Tests: the test index is created in pytest_sessionstart, before collection imports search_setup.
  • Version: CRAWLER_VERSION goes to 1.0.1, since crawl.py and apps.py are crawler code.

Why

Creating the index on startup had two problems:

  • Silent empty index in production. If the data volume failed to mount, the server would start on a new, empty index instead of failing.
  • Side effects everywhere. Every process that set Django up wrote an index: tests, management commands, and even a plain import mwmbl.crawl, which wrote 400MB. That import now writes only the 11MB external cache.

Deploying

  • Production and beta: both already have an index, so nothing changes for them.
  • New environments: a new server environment now needs manage.py create_index run once. Without it, the server fails at startup and the healthcheck fails the deploy.
  • Contributors: existing checkouts keep their devdata/index-v2.tinysearch. New ones get it from make install.

Verification

  • The full test suite passes from an empty /tmp/test_mwmbl_data: 1646 passed, 9 skipped.
  • New tests in test/test_create_index_command.py check three things:
    • ready() creates the external cache but not the search index;
    • the command creates an index of the configured size;
    • the crawler's main() creates its index before it starts crawling.
  • make check passes.
  • The import-only crawler check (python -c "from mwmbl.crawl import run" with a fresh HOME) now leaves only external-cache.tinysearch behind.
  • Not covered by a unit test: the two refusals in search_setup.py. They run at module import, which the test session has already done.

🤖 Generated with Claude Code

8000
MwmblConfig.ready() created the search index whenever it was missing, so a data volume
that failed to mount gave a server running on an empty index, and every process that set
Django up wrote one - including a plain import of mwmbl.crawl (400MB).

- ready() now creates only the external cache, which is disposable.
- New `manage.py create_index` command, run by `make install` (`make create-index`).
- search_setup refuses to start on a missing index or one whose shape disagrees with
  NUM_PAGES, keeping the protection ready() gave the production index.
- The crawler's main() creates its own index, so volunteers still need no setup step.
- Tests create theirs in pytest_sessionstart.
- CRAWLER_VERSION 1.0.1, since the crawler's startup changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov
codecov Bot commented Oct 28, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mwmbl/search_setup.py 66.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Base automatically changed from crawler-v1.0.0 to main October 29, 2026 15:56
The URL check imports search_setup, which now fails when the index is
missing, so the command died before it could create the index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DTbu4qL49ukb9EUc7Fn9fg
@daoudclarke
daoudclarke merged commit d999099 into main Oct 30, 2026
7 checks passed
@daoudclarke
daoudclarke deleted the explicit-create-index branch October 30, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0