perf: index kudos ledger on hot path

This commit is contained in:
tazlin committed 2026-09-01 00:00:53 -04:00
1 parent 6fde1004f6
commit e0b0c361fe
6 files changed
+35 -3

No files matched your search

+4
View File
@@ -148,6 +148,10 @@ class KudosLedger(db.Model): # type: ignore[name-defined,misc]
"user_id",
postgresql_where=column("applied").is_(false()),
),
# available_kudos() sums a payer's unapplied debits on every admission. The plain user_id index holds the
# payer's entire history, so this covers only the pending rows. Existing deployments add it with
# sql_statements/5.1.11.txt.
Index("ix_kudos_ledger_unapplied_by_user", "user_id", postgresql_where=column("applied").is_(false())),
)
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
+1 -1
View File
@@ -7,7 +7,7 @@ from horde_sdk.generation_parameters.image.constraints import (
KNOWN_SAMPLER_SOLVER_TYPES,
)
HORDE_VERSION = "5.1.9"
HORDE_VERSION = "5.1.11"
HORDE_API_VERSION = "2.6"
WHITELISTED_SERVICE_IPS = {
+1 -1
View File
@@ -5,7 +5,7 @@
[project]
name = "AI-Horde"
version = "5.1.9"
version = "5.1.11"
description = "A Crowdsourced Generative AI cluster for everyone."
authors = [
{name = "db0", email = "mail@dbzer0.com"},
+25
View File
@@ -0,0 +1,25 @@
-- Run with psql in its default autocommit mode. Do not pass --single-transaction:
-- CREATE INDEX CONCURRENTLY cannot run inside a transaction block. Pass
-- -v ON_ERROR_STOP=1 so a failure stops the migration. A failed concurrent build
-- leaves an INVALID index; drop it and rerun after correcting the cause.
--
-- available_kudos() (request admission) sums a payer's unapplied debits:
-- SELECT ... FROM kudos_ledger WHERE user_id = ? AND applied IS FALSE AND ...
-- The plain user_id index covers the payer's whole history, so a busy payer
-- (the anonymous account above all) walked millions of applied rows to find a
-- handful of pending ones. This partial index covers exactly the pending rows
-- and stays small. Index-only: no application change depends on it, so it can
-- be applied before or after deploying 5.1.11.
SET lock_timeout = '3s';
CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_kudos_ledger_unapplied_by_user
ON kudos_ledger (user_id)
WHERE applied IS FALSE;
-- The partial "unapplied"/"drainable" indexes gain an entry for every inserted
-- row and lose it only when vacuum removes the flipped tuple; a period of slow
-- vacuuming leaves them mostly dead entries that every claim scan and health
-- aggregate must walk. Rebuild them online if pg_relation_size() is out of all
-- proportion to the live pending row count.
-- REINDEX INDEX CONCURRENTLY ix_kudos_ledger_unapplied;
-- REINDEX INDEX CONCURRENTLY ix_kudos_stat_events_drainable;
+3
View File
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Tazlin <tazlin@haidra.net>
SPDX-License-Identifier: AGPL-3.0-or-later
Generated
+1 -1
View File
@@ -4,7 +4,7 @@ requires-python = ">=3.12, <3.14"
[[package]]
name = "ai-horde"
version = "5.1.9"
version = "5.1.11"
source = { virtual = "." }
dependencies = [
{ name = "alt-profanity-check" },