Add index job_build_idx on build

This speeds up loading / by ~10x
This commit is contained in:
Reynir Björnsson 2021-02-02 10:23:54 +01:00
parent 6b96cae318
commit 03fe06be87
3 changed files with 44 additions and 2 deletions

View file

@ -65,6 +65,16 @@ let r20210126 =
Cmdliner.Term.(const do_database_action $ const M20210126.rollback $ setup_log $ dbpath),
Cmdliner.Term.info ~doc "rollback-2021-01-26"
let m20210202 =
let doc = "Adds an index 'job_build_idx' on 'build' (2021-02-02)" in
Cmdliner.Term.(const do_database_action $ const M20210202.migrate $ setup_log $ dbpath),
Cmdliner.Term.info ~doc "migrate-2021-02-02"
let r20210202 =
let doc = "Rollback index 'job_build_idx' on 'build' (2021-02-02)" in
Cmdliner.Term.(const do_database_action $ const M20210202.rollback $ setup_log $ dbpath),
Cmdliner.Term.info ~doc "rollback-2021-02-02"
let help_cmd =
let topic =
let doc = "Migration to get help on" in
@ -82,6 +92,8 @@ let default_cmd =
let () =
Cmdliner.Term.eval_choice
default_cmd
[help_cmd;
m20210126; r20210126]
[ help_cmd;
m20210126; r20210126;
m20210202; r20210202;
]
|> Cmdliner.Term.exit

View file

@ -0,0 +1,26 @@
open Rresult.R.Infix
let migrate (module Db : Caqti_blocking.CONNECTION) =
let job_build_idx =
Caqti_request.exec ~oneshot:true
Caqti_type.unit
"CREATE INDEX job_build_idx ON build(job)";
in
Db.find Builder_db.get_application_id () >>= fun application_id ->
Db.find Builder_db.get_version () >>= fun user_version ->
if application_id <> Builder_db.application_id || user_version <> 1L
then Error (`Wrong_version (application_id, user_version))
else Db.exec job_build_idx ()
let rollback (module Db : Caqti_blocking.CONNECTION) =
let q =
Caqti_request.exec ~oneshot:true
Caqti_type.unit
"DROP INDEX IF EXISTS job_build_idx"
in
Db.find Builder_db.get_application_id () >>= fun application_id ->
Db.find Builder_db.get_version () >>= fun user_version ->
if application_id <> Builder_db.application_id || user_version <> 1L
then Error (`Wrong_version (application_id, user_version))
else
Db.exec q ()

View file

@ -474,6 +474,8 @@ let migrate = [
Build_artifact.migrate;
Build_file.migrate;
User.migrate;
Caqti_request.exec Caqti_type.unit
"CREATE INDEX job_build_idx ON build(job)";
set_current_version;
set_application_id;
]
@ -484,6 +486,8 @@ let rollback = [
Build_artifact.rollback;
Build.rollback;
Job.rollback;
Caqti_request.exec Caqti_type.unit
"DROP INDEX IF EXISTS job_build_idx";
Caqti_request.exec Caqti_type.unit
"PRAGMA user_version = 0";
Caqti_request.exec Caqti_type.unit