summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Daenney <daenney@users.noreply.github.com>2023-12-16 12:54:53 +0100
committerLibravatar GitHub <noreply@github.com>2023-12-16 12:54:53 +0100
commitfbe4e60232a56e2eb807384407081404963f092b (patch)
tree214dd8af7c3ded47a48ffeffbf125f54c1de22d7
parent[performance] simpler throttling logic (#2407) (diff)
downloadgotosocial-fbe4e60232a56e2eb807384407081404963f092b.tar.xz
[feature] Run ANALYZE after migrations on SQLite (#2428)
* [feature] Run ANALYZE after migrations on SQLite This ensures that at the end of migrations, we run ANALYZE if we're using SQLite. This should be relatively quick and guarantees that the table and index statistics have been updated. This helps to ensure the query planner makes better choices when it comes to picking which indexes are used when running queries. * [chore] use ExecContext Uses ExecContext so we pass the context through, this is helpful for anyone running with tracing enabled
-rw-r--r--internal/db/bundb/bundb.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go
index 2559b8d58..f7417cfeb 100644
--- a/internal/db/bundb/bundb.go
+++ b/internal/db/bundb/bundb.go
@@ -44,6 +44,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/tracing"
"github.com/uptrace/bun"
+ "github.com/uptrace/bun/dialect"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/dialect/sqlitedialect"
"github.com/uptrace/bun/migrate"
@@ -113,6 +114,14 @@ func doMigration(ctx context.Context, db *bun.DB) error {
}
log.Infof(ctx, "MIGRATED DATABASE TO %s", group)
+
+ if db.Dialect().Name() == dialect.SQLite {
+ log.Info(ctx, "running ANALYZE to update table and index statistics")
+ _, err := db.ExecContext(ctx, "ANALYZE")
+ if err != nil {
+ log.Warnf(ctx, "ANALYZE failed, query planner may make poor life choices: %s", err)
+ }
+ }
return nil
}