This commit is contained in:
tobi 2025-09-29 18:56:44 +02:00 committed by tobi
commit 9c544e732c

View file

@ -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").