From 33b595973a94c9b45cb33f87691156120492f5b6 Mon Sep 17 00:00:00 2001 From: rays Date: Sun, 22 Nov 2026 08:54:42 -0500 Subject: [PATCH] Counting the files waiting to download reads an index of them alone (#489) Db::counts counted enclosures WHERE state = 'pending' with no index to use: a parallel sequential scan of all ~690,000 rows in production, 92 ms and 32,397 buffers, every 30 s for /metrics and on each /api/status, to find a handful. It was the slowest route at p95 and once 1.1 s. A partial index on the pending rows makes it an index-only count of those few, as enclosures_on_disk already does for the downloaded count beside it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01RqkrVBuJRne2JAhFpaDV2U --- crates/ipx/CHANGELOG.md | 1 + crates/ipx/src/db.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/crates/ipx/CHANGELOG.md b/crates/ipx/CHANGELOG.md index 5a74c93..1aada34 100644 --- a/crates/ipx/CHANGELOG.md +++ b/crates/ipx/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Counting the files waiting to download, which the status and the metrics do every 30 seconds, reads only those files instead of every one ipx knows of: about 1 ms instead of 90 (#489). - Downloading a season takes back the files of it retention removed, rather than queuing nothing, and no file on its way already is queued twice (#483). - A feed an OPML stops listing leaves All Subscriptions with it, rather than its items staying there with no feed name beside them: the scan no longer reads it again after the list drops it, and its subscriptions go with it, as they do when a feed is removed with `ipx rm`. Any left from before are removed when ipx starts (#478). - Searching All Subscriptions answers in a fraction of a second, not five: a search reads each item's title and text without its markup, indexed on Postgres, and still finds part of a word. It no longer matches words inside the HTML's tags, such as a link's address. Text past the first 4,000 characters of a very long post is not searched (#459, #472). diff --git a/crates/ipx/src/db.rs b/crates/ipx/src/db.rs index a064b8b..4758a9c 100644 --- a/crates/ipx/src/db.rs +++ b/crates/ipx/src/db.rs @@ -84,6 +84,9 @@ async fn create_missing(orm: &DatabaseConnection) -> Result<()> { // files through enclosures_entry read every file row of their feeds, 58 ms a feed list // (#165). Also what the healthcheck's count and the Downloaded filter look for. "CREATE INDEX IF NOT EXISTS enclosures_on_disk ON enclosures (feed_id, guid) WHERE path IS NOT NULL", + // The few files waiting to download, which the status counts every 30 s: without it, a + // scan of all 690,000 enclosures, 92 ms each time, to find a handful (#489). + "CREATE INDEX IF NOT EXISTS enclosures_pending ON enclosures (id) WHERE state = 'pending'", "CREATE UNIQUE INDEX IF NOT EXISTS users_name_lower ON users (lower(name))", // Every key and date an item list sorts by, so `entries_where` pages from the index alone // and visits the table only for the rows it shows. Sorting All Subscriptions from the