few more little tweaks

This commit is contained in:
tobi 2025-09-29 11:59:35 +02:00
commit 228b41cb53

View file

@ -136,13 +136,13 @@ func init() {
if percentDone <= 100 { if percentDone <= 100 {
log.Infof( log.Infof(
ctx, ctx,
"[updated %d total rows, now @ ~%.0f rows/s] done ~%.2f%% of statuses", "[~%.0f rows/s; updated %d total rows] migrated ~%.2f%% of statuses",
updatedRowsTotal, rowsPerSecond, percentDone, updatedRowsTotal, rowsPerSecond, percentDone,
) )
} else { } else {
log.Infof( log.Infof(
ctx, ctx,
"[updated %d total rows, now @ ~%.0f rows/s] almost done... ", "[~%.0f rows/s; updated %d total rows] almost done... ",
updatedRowsTotal, rowsPerSecond, updatedRowsTotal, rowsPerSecond,
) )
} }
@ -268,14 +268,33 @@ func (sr *statusRethreader) rethreadStatus(ctx context.Context, tx bun.Tx, statu
// This may have changed from // This may have changed from
// the initial batch selection // the initial batch selection
// to the rethreadStatus() call. // to the rethreadStatus() call.
upToDateValues := make(map[string]any, 3)
if err := tx.NewSelect(). if err := tx.NewSelect().
Model(status). TableExpr("? AS ?", bun.Ident("statuses"), bun.Ident("status")).
Column("in_reply_to_id", "thread_id"). Column("in_reply_to_id", "thread_id", "thread_id_new").
Where("? = ?", bun.Ident("id"), status.ID). Where("? = ?", bun.Ident("id"), status.ID).
Scan(ctx); err != nil { Scan(ctx, &upToDateValues); err != nil {
return 0, gtserror.Newf("error selecting status: %w", err) return 0, gtserror.Newf("error selecting status: %w", err)
} }
// If we've just threaded this status by setting
// thread_id_new, then by definition anything we
// could find from the entire thread must now be
// threaded, so we can save some database calls
// by skipping iterating up + down from here.
if v, ok := upToDateValues["thread_id_new"]; ok && v.(string) != id.Lowest {
log.Debug(ctx, "skipping just rethreaded status")
return 0, nil
}
// Set up-to-date values on the status.
if inReplyToID, ok := upToDateValues["in_reply_to_id"]; ok && inReplyToID != nil {
status.InReplyToID = inReplyToID.(string)
}
if threadID, ok := upToDateValues["thread_id"]; ok && threadID != nil {
status.ThreadID = threadID.(string)
}
// status and thread ID cursor // status and thread ID cursor
// index values. these are used // index values. these are used
// to keep track of newly loaded // to keep track of newly loaded
@ -328,6 +347,7 @@ func (sr *statusRethreader) rethreadStatus(ctx context.Context, tx bun.Tx, statu
// batch of statuses is already correctly // batch of statuses is already correctly
// threaded. Then we have nothing to do! // threaded. Then we have nothing to do!
if sr.allThreaded && len(sr.threadIDs) == 1 { if sr.allThreaded && len(sr.threadIDs) == 1 {
log.Debug(ctx, "skipping just rethreaded thread")
return 0, nil return 0, nil
} }