mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-22 18:22:11 +00:00
[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
This commit is contained in:
parent
d56a8d095e
commit
fbe4e60232
|
@ -44,6 +44,7 @@
|
|||
"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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue