Skip to content

Commit

Permalink
sqlite: add msg type index to speed up cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
brunnre8 committed Dec 24, 2023
1 parent b0ca8e5 commit edb1226
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/plugins/messageStorage/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ try {
type Migration = {version: number; stmts: string[]};
type Rollback = {version: number; rollback_forbidden?: boolean; stmts: string[]};

export const currentSchemaVersion = 1679743888000; // use `new Date().getTime()`
export const currentSchemaVersion = 1703322560448; // use `new Date().getTime()`

// Desired schema, adapt to the newest version and add migrations to the array below
const schema = [
Expand All @@ -45,6 +45,7 @@ const schema = [
)`,
"CREATE INDEX network_channel ON messages (network, channel)",
"CREATE INDEX time ON messages (time)",
"CREATE INDEX msg_type_idx on messages (type)", // needed for efficient storageCleaner queries
];

// the migrations will be executed in an exclusive transaction as a whole
Expand Down Expand Up @@ -78,6 +79,10 @@ export const migrations: Migration[] = [
)`,
],
},
{
version: 1703322560448,
stmts: ["CREATE INDEX msg_type_idx on messages (type)"],
},
];

// down migrations need to restore the state of the prior version.
Expand All @@ -91,6 +96,10 @@ export const rollbacks: Rollback[] = [
version: 1679743888000,
stmts: [], // here we can't drop the tables, as we use them in the code, so just leave those in
},
{
version: 1703322560448,
stmts: ["drop INDEX msg_type_idx"],
},
];

class Deferred {
Expand Down

0 comments on commit edb1226

Please sign in to comment.