From d2127361657748b14281f84011e1f2f660d12b89 Mon Sep 17 00:00:00 2001 From: tobi Date: Mon, 29 Sep 2025 18:56:44 +0200 Subject: [PATCH] boobs --- .../20250415111056_thread_all_statuses.go | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/db/bundb/migrations/20250415111056_thread_all_statuses.go b/internal/db/bundb/migrations/20250415111056_thread_all_statuses.go index a4b910fa6..daf392ee6 100644 --- a/internal/db/bundb/migrations/20250415111056_thread_all_statuses.go +++ b/internal/db/bundb/migrations/20250415111056_thread_all_statuses.go @@ -106,7 +106,7 @@ func init() { Where("? IS NULL", bun.Ident("in_reply_to_id")). Where("? < ?", bun.Ident("id"), maxID). OrderExpr("? DESC", bun.Ident("id")). - Limit(500). + Limit(100). Scan(ctx); err != nil && !errors.Is(err, sql.ErrNoRows) { return gtserror.Newf("error selecting top-level statuses: %w", err) } @@ -173,6 +173,19 @@ func init() { return err } + // Reset max ID. + maxID = id.Highest + + // Create a temporary index on thread_id_new for stragglers. + log.Info(ctx, "creating temporary statuses thread_id_new index") + if _, err := db.NewCreateIndex(). + Table("statuses"). + Index("statuses_thread_id_new_idx"). + Column("thread_id_new"). + Exec(ctx); err != nil { + return gtserror.Newf("error creating new thread_id index: %w", err) + } + // Open a new transaction lads. tx, err = db.BeginTx(ctx, nil) if err != nil { @@ -192,8 +205,8 @@ func init() { if err := tx.NewSelect(). Model(&statuses). Column("id"). - Where("? IS NULL", bun.Ident("thread_id")). - Limit(250). + Where("? = ?", bun.Ident("thread_id_new"), id.Lowest). + Limit(500). Scan(ctx); err != nil && !errors.Is(err, sql.ErrNoRows) { return gtserror.Newf("error selecting unthreaded statuses: %w", err) } @@ -253,6 +266,13 @@ func init() { ) } + log.Info(ctx, "dropping temporary thread_id_new index") + if _, err := db.NewDropIndex(). + Index("statuses_thread_id_new_idx"). + Exec(ctx); err != nil { + return gtserror.Newf("error dropping temporary thread_id_new index: %w", err) + } + log.Info(ctx, "dropping old thread_to_statuses table") if _, err := db.NewDropTable(). Table("thread_to_statuses").