SQL: Add packages.c_hasman cache to speed up package listings

Going from average ~100ms to ~10ms or so. The previous query had a
tendency to be much slower sometimes, let's see if this cache also takes
care of those outliers.

Migration script:

  ALTER TABLE packages ADD COLUMN c_hasman boolean NOT NULL DEFAULT FALSE;

  DROP INDEX packages_system_name_key;
  CREATE UNIQUE INDEX packages_system_name_key ON packages (system, name) INCLUDE (id, c_hasman, dead);

  UPDATE packages SET c_hasman = NOT c_hasman
   WHERE c_hasman <> EXISTS(SELECT 1 FROM package_versions pv WHERE pv.package = packages.id AND EXISTS(SELECT 1 FROM files f WHERE f.pkgver = pv.id));
This commit is contained in:
Yorhel 2024-04-29 21:12:54 +02:00
parent 5d56bded66
commit 1ee5c9c2df
4 changed files with 34 additions and 15 deletions

View file

@ -56,7 +56,12 @@ CREATE TABLE packages (
-- Packages where the latest version does not have any man pages may also be
-- marked as dead even if the package is still available in the repos.
dead boolean NOT NULL DEFAULT FALSE,
UNIQUE(system, name)
-- Whether this package has at least one man page indexed in the database.
-- The indexer uses this table to keep track of which packages it has
-- already indexed, but not all packages seen by the indexer have a man page.
-- This cache helps the web front-end filter out irrelevant packages faster.
c_hasman boolean NOT NULL DEFAULT FALSE,
UNIQUE(system, name) INCLUDE (id, c_hasman, dead)
);