From 2d7da509e73418099c5a49a34b2b99e1295839bf Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Wed, 27 Dec 2023 13:27:05 +0100 Subject: [PATCH] fix(GODT-3183): Add index to message flags Should improve performance in join operation and general lookups. --- internal/db_impl/sqlite3/migrations.go | 2 ++ internal/db_impl/sqlite3/v3/migration.go | 26 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 internal/db_impl/sqlite3/v3/migration.go diff --git a/internal/db_impl/sqlite3/migrations.go b/internal/db_impl/sqlite3/migrations.go index 5e9a5316..93585639 100644 --- a/internal/db_impl/sqlite3/migrations.go +++ b/internal/db_impl/sqlite3/migrations.go @@ -11,6 +11,7 @@ import ( v0 "github.com/ProtonMail/gluon/internal/db_impl/sqlite3/v0" v1 "github.com/ProtonMail/gluon/internal/db_impl/sqlite3/v1" v2 "github.com/ProtonMail/gluon/internal/db_impl/sqlite3/v2" + v3 "github.com/ProtonMail/gluon/internal/db_impl/sqlite3/v3" "github.com/sirupsen/logrus" ) @@ -22,6 +23,7 @@ var migrationList = []Migration{ &v0.Migration{}, &v1.Migration{}, &v2.Migration{}, + &v3.Migration{}, } func RunMigrations(ctx context.Context, tx utils.QueryWrapper, generator imap.UIDValidityGenerator) error { diff --git a/internal/db_impl/sqlite3/v3/migration.go b/internal/db_impl/sqlite3/v3/migration.go new file mode 100644 index 00000000..24e40b2b --- /dev/null +++ b/internal/db_impl/sqlite3/v3/migration.go @@ -0,0 +1,26 @@ +package v3 + +import ( + "context" + "fmt" + v1 "github.com/ProtonMail/gluon/internal/db_impl/sqlite3/v1" + + "github.com/ProtonMail/gluon/imap" + "github.com/ProtonMail/gluon/internal/db_impl/sqlite3/utils" +) + +type Migration struct{} + +func (m Migration) Run(ctx context.Context, tx utils.QueryWrapper, _ imap.UIDValidityGenerator) error { + // Create an index on message id field to speed up lookup queries for message flags. + query := fmt.Sprintf("create index message_flags_message_id_index on %v (%v)", + v1.MessageFlagsTableName, + v1.MessageFlagsFieldMessageID, + ) + + if _, err := utils.ExecQuery(ctx, tx, query); err != nil { + return fmt.Errorf("failed to create connector settings table: %w", err) + } + + return nil +}