github NepiRaw/Stremio-SubSense v2.4.0

latest releases: v2.4.3, v2.4.2, v2.4.1...
3 months ago

SubSense v2.4.0 "db-rework"

This release rebuilds how SubSense stores and counts things. It exists because of different production issues.

Nothing about the addon's behaviour for end users changes: same manifest, same configuration URLs, same subtitles. Existing installs keep working. Self-hosters must run a one-time migration, see Upgrading.


What changed

Storage: one database became three

subsense.db is replaced by subsense-cache.db, subsense-stats.db and subsense-meta.db.

They are separate files so they have separate lock domains. Under v2 an analytics query could hold the same lock the subtitle path needed. Now it cannot, by construction.

The old file is never opened by v2.4.0, which is what makes rollback clean.

A Redis hot path

Built responses now live in Redis, shared across every API worker. On a cache hit, serving a request touches no disk and makes no upstream call.

Redis is a cache and a delta buffer, never a source of truth. If Redis goes down the addon keeps serving from SQLite: analytics stop, /health/deep reports redis, and users see subtitles.

The API runs as a cluster

WEB_CONCURRENCY request workers behind one port, with a primary that forks them, replaces any that die, and relays shutdown signals. A single process was saturating one core at peak.

This surfaced two bugs that single-process testing could not:

  • busy_timeout was applied after auto_vacuum and journal_mode, so those two raced with a zero timeout. Two of three workers died at boot with SQLITE_BUSY. It is now the first pragma on every connection.
  • AnimeTosho and OpenSubtitles spaced their upstream requests with per-process timers, so three workers would have tripled the real upstream rate. Slots are now reserved atomically in Redis.

A maintenance worker owns all background work

Eight jobs, each with a time budget it reports against. A job does what fits, logs what it left, and returns.


Upgrading from v2.3.x

Run the migration before starting v2.4.0 for the first time. The new version does not read subsense.db, so without migrating you start on empty databases. Worse, the API creates the new database files at boot, so migrating afterwards means discarding whatever the new stack recorded.

Your data is not at risk either way: the migration only ever reads the old file.

1. Stop the old stack

docker compose down

2. Run the migration

docker run --rm \
  -v <your-data-volume>:/app/data \
  -e CACHE_DB_PATH=/app/data/subsense-cache.db \
  -e STATS_DB_PATH=/app/data/subsense-stats.db \
  -e META_DB_PATH=/app/data/subsense-meta.db \
  nepiraw/stremio-subsense:latest \
  node scripts/migrate-db.js --old=/app/data/subsense.db

Use -v /path/to/data:/app/data if you bind-mount a directory rather than using a named volume.

It prints a per-table report and exits nonzero if any table copied a different number of rows than the source held. If that happens, do not start v2.4.0: delete the partial subsense-*.db files and investigate.

Add --dry-run first to see the counts without writing anything.

Expect it to take seconds to a couple of minutes depending on cache size. On a 660 MB subtitle cache the bulk copy runs at roughly 65 MB/s.

3. Start the new stack

You now need three containers: API, worker, and Redis. The compose file is in the README under Self-Hosting.

What gets carried over

Carried Left behind
user_tracking, lifetime and daily statistics request_log and user_content_log rows
provider_stats, language_stats cache_stats_summary, replaced by write-time counters
Subtitle cache entries newer than L2_TTL_DAYS Cache entries already past their TTL
AniDB and AnimeTosho metadata caches

Environment variable changes

Removed:

Variable Replacement
STATS_REFRESH_INTERVAL STATS_ENABLED=false
DB_PATH CACHE_DB_PATH, STATS_DB_PATH, META_DB_PATH
CACHE_RETENTION_DAYS L2_TTL_DAYS
CACHE_REFRESH_INTERVAL L1_STALE_AFTER_HOURS
ENABLE_CACHE Nothing. Caching is no longer optional
WORKER_OPTIMIZE_INTERVAL_MS Nothing. The optimize pass folded into the checkpoint job

New, worth setting:

Variable Default Note
REDIS_URL redis://127.0.0.1:6379 Required in practice; without Redis the addon runs permanently degraded
WEB_CONCURRENCY 1 Set to your core count. Production runs 3
CACHE_DB_PATH / STATS_DB_PATH / META_DB_PATH under ./data The three database files
L1_TTL_HOURS / L1_STALE_AFTER_HOURS 6 / 2 Redis response cache freshness
L2_TTL_DAYS 7 Subtitle cache retention
HEALTH_HEARTBEAT_MAX_SECONDS 300 When /health/deep calls the worker dead

Rolling back

Put your old compose back and start it. v2.4.0 never opens subsense.db, so it is exactly as v2
left it. Statistics recorded while v2.4.0 was running stay in the new files and do not come back.

Don't miss a new Stremio-SubSense release

NewReleases is sending notifications on new releases.