Private
Public Access
Index Postgres search and harden SQLite search/concurrency (C5, C6)
Postgres recomputed a tsvector over every article's full text on every search. A migration now adds a stored, GIN-indexed search_vector column kept current by a trigger (so no ingest/update path can forget it), and the backend reads that column. Untested here: no Postgres in the dev sandbox, so the SQL is reviewed but not executed — worth one run of the (skipped-on-SQLite) Postgres test module against a real instance. SQLite search built one bound parameter per subscribed feed, so enough feeds would exceed the variable limit, and the OperationalError was swallowed into "no results". It now scopes through a subquery on Subscription and logs failures. SQLite connections also get WAL mode, a 20s busy timeout, and IMMEDIATE transactions so gunicorn, Celery, and the FTS triggers stop tripping over each other. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb0ce5a336
commit
70b0d4f277
4 files changed
+104
-21
No files matched your search
@@ -77,6 +77,21 @@ ASGI_APPLICATION = "config.asgi.application"
|
||||
# postgres://user:pass@host:5432/dbname
|
||||
DATABASES = {"default": env.db_url("DATABASE_URL", default=f"sqlite:///{BASE_DIR / 'db.sqlite3'}")}
|
||||
|
||||
# gunicorn, Celery workers, and the FTS triggers all write to the same
|
||||
# SQLite file (C6): without WAL, readers and a writer block each other,
|
||||
# and without a busy timeout a contended write fails immediately with
|
||||
# "database is locked" instead of waiting its turn. IMMEDIATE takes the
|
||||
# write lock at transaction start so a read-then-write transaction can't
|
||||
# deadlock upgrading it mid-way.
|
||||
if DATABASES["default"]["ENGINE"] == "django.db.backends.sqlite3":
|
||||
DATABASES["default"].setdefault("OPTIONS", {}).update(
|
||||
{
|
||||
"timeout": 20,
|
||||
"transaction_mode": "IMMEDIATE",
|
||||
"init_command": "PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL;",
|
||||
}
|
||||
)
|
||||
|
||||
AUTH_USER_MODEL = "accounts.User"
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
|
||||
Reference in new issue
Block a user