From 65ca4815250dfab9e18d31ef641bad309403280c Mon Sep 17 00:00:00 2001 From: rays Date: Fri, 9 Oct 2026 02:15:17 +0000 Subject: [PATCH] Index the file rows with a file on disk (#165) Counting a person's files through enclosures_entry, once the count was of their own feeds only, read every file row of their 146 feeds to find the few with a file: 58 ms of a feed list, more than the 37-50 ms the count over every row of the table had taken. Production holds 15 files among many thousand rows. A partial index on the rows with a path holds just those, and serves the healthcheck's count and the Downloaded filter too. Co-Authored-By: Claude Opus 5.5 --- src/db.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/db.rs b/src/db.rs index 15dbbb6..921a980 100644 --- a/src/db.rs +++ b/src/db.rs @@ -65,6 +65,10 @@ async fn create_missing(orm: &sea_orm::DatabaseConnection) -> Result<()> { } for sql in [ "CREATE INDEX IF NOT EXISTS enclosures_entry ON enclosures (feed_id, guid)", + // The few rows with a file on disk, 15 of the server's many thousand: counting a person's + // 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", "CREATE UNIQUE INDEX IF NOT EXISTS users_name_lower ON users (lower(name))", ] { orm.execute_unprepared(sql).await.with_context(|| sql.to_owned())?;