mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Apply indexes after upgrades
This commit is contained in:
parent
cbf043ac7e
commit
11b4f642a6
3 changed files with 109 additions and 0 deletions
32
databases/_private_indexes.sql
Normal file
32
databases/_private_indexes.sql
Normal file
|
@ -0,0 +1,32 @@
|
|||
-- sponsorTimes
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "idx_16928_sponsorTimes_hashedIP"
|
||||
ON public."sponsorTimes" USING btree
|
||||
("hashedIP" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "sponsorTimes_hashedIP"
|
||||
ON public."sponsorTimes" USING btree
|
||||
("hashedIP" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- votes
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "votes_userID"
|
||||
ON public.votes USING btree
|
||||
("UUID" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- shadowBannedUsers
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "shadowBannedUsers_index"
|
||||
ON public."shadowBannedUsers" USING btree
|
||||
("userID" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- categoryVotes
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "categoryVotes_UUID"
|
||||
ON public."categoryVotes" USING btree
|
||||
("UUID" COLLATE pg_catalog."default" ASC NULLS LAST, "userID" COLLATE pg_catalog."default" ASC NULLS LAST, "hashedIP" COLLATE pg_catalog."default" ASC NULLS LAST, category COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
66
databases/_sponsorTimes_indexes.sql
Normal file
66
databases/_sponsorTimes_indexes.sql
Normal file
|
@ -0,0 +1,66 @@
|
|||
-- sponsorTimes
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "sponsorTiems_timeSubmitted"
|
||||
ON public."sponsorTimes" USING btree
|
||||
("timeSubmitted" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "sponsorTime_userID"
|
||||
ON public."sponsorTimes" USING btree
|
||||
("userID" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "sponsorTimes_UUID"
|
||||
ON public."sponsorTimes" USING btree
|
||||
("UUID" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "sponsorTimes_hashedVideoID"
|
||||
ON public."sponsorTimes" USING btree
|
||||
("hashedVideoID" COLLATE pg_catalog."default" ASC NULLS LAST, category COLLATE pg_catalog."default" ASC NULLS LAST, "startTime" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "sponsorTimes_videoID"
|
||||
ON public."sponsorTimes" USING btree
|
||||
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, service COLLATE pg_catalog."default" ASC NULLS LAST, category COLLATE pg_catalog."default" ASC NULLS LAST, "timeSubmitted" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- userNames
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "userNames_userID"
|
||||
ON public."userNames" USING btree
|
||||
("userID" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- vipUsers
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "vipUsers_index"
|
||||
ON public."vipUsers" USING btree
|
||||
("userID" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- warnings
|
||||
|
||||
CREATE INDEX IF NOT EXISTS warnings_index
|
||||
ON public.warnings USING btree
|
||||
("userID" COLLATE pg_catalog."default" ASC NULLS LAST, "issueTime" DESC NULLS LAST, enabled DESC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "warnings_issueTime"
|
||||
ON public.warnings USING btree
|
||||
("issueTime" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- noSegments
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "noSegments_videoID"
|
||||
ON public."noSegments" USING btree
|
||||
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, category COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
||||
|
||||
-- categoryVotes
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "categoryVotes_UUID_public"
|
||||
ON public."categoryVotes" USING btree
|
||||
("UUID" COLLATE pg_catalog."default" ASC NULLS LAST, category COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||
TABLESPACE pg_default;
|
|
@ -23,6 +23,8 @@ export class Postgres implements IDatabase {
|
|||
|
||||
// Upgrade database if required
|
||||
await this.upgradeDB(this.config.fileNamePrefix, this.config.dbSchemaFolder);
|
||||
|
||||
await this.applyIndexes(this.config.fileNamePrefix, this.config.dbSchemaFolder);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +120,15 @@ export class Postgres implements IDatabase {
|
|||
Logger.debug('db update: no file ' + path);
|
||||
}
|
||||
|
||||
private async applyIndexes(fileNamePrefix: string, schemaFolder: string) {
|
||||
const path = schemaFolder + "/_" + fileNamePrefix + "_indexes.sql";
|
||||
if (fs.existsSync(path)) {
|
||||
await this.pool.query(fs.readFileSync(path).toString());
|
||||
} else {
|
||||
Logger.debug('failed to apply indexes to ' + fileNamePrefix);
|
||||
}
|
||||
}
|
||||
|
||||
private processUpgradeQuery(query: string): string {
|
||||
let result = query;
|
||||
result = result.replace(/sha256\((.*?)\)/gm, "digest($1, 'sha256')");
|
||||
|
|
Loading…
Reference in a new issue