mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
Only show one title/thumbnail per userID
This commit is contained in:
@@ -124,6 +124,11 @@ CREATE INDEX IF NOT EXISTS "titles_timeSubmitted"
|
|||||||
("timeSubmitted" ASC NULLS LAST)
|
("timeSubmitted" ASC NULLS LAST)
|
||||||
TABLESPACE pg_default;
|
TABLESPACE pg_default;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "titles_votes_timeSubmitted"
|
||||||
|
ON public."titles" USING btree
|
||||||
|
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, "service" COLLATE pg_catalog."default" ASC NULLS LAST, "votes" DESC NULLS LAST, "timeSubmitted" DESC NULLS LAST)
|
||||||
|
TABLESPACE pg_default;
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS "titles_videoID"
|
CREATE INDEX IF NOT EXISTS "titles_videoID"
|
||||||
ON public."titles" USING btree
|
ON public."titles" USING btree
|
||||||
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, "service" COLLATE pg_catalog."default" ASC NULLS LAST)
|
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, "service" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||||
@@ -141,6 +146,11 @@ CREATE INDEX IF NOT EXISTS "thumbnails_timeSubmitted"
|
|||||||
("timeSubmitted" ASC NULLS LAST)
|
("timeSubmitted" ASC NULLS LAST)
|
||||||
TABLESPACE pg_default;
|
TABLESPACE pg_default;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "thumbnails_votes_timeSubmitted"
|
||||||
|
ON public."thumbnails" USING btree
|
||||||
|
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, "service" COLLATE pg_catalog."default" ASC NULLS LAST, "votes" DESC NULLS LAST, "timeSubmitted" DESC NULLS LAST)
|
||||||
|
TABLESPACE pg_default;
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS "thumbnails_videoID"
|
CREATE INDEX IF NOT EXISTS "thumbnails_videoID"
|
||||||
ON public."thumbnails" USING btree
|
ON public."thumbnails" USING btree
|
||||||
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, "service" COLLATE pg_catalog."default" ASC NULLS LAST)
|
("videoID" COLLATE pg_catalog."default" ASC NULLS LAST, "service" COLLATE pg_catalog."default" ASC NULLS LAST)
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ export async function getVideoBranding(res: Response, videoID: VideoID, service:
|
|||||||
"all",
|
"all",
|
||||||
`SELECT "titles"."title", "titles"."original", "titleVotes"."votes", "titleVotes"."locked", "titleVotes"."shadowHidden", "titles"."UUID", "titles"."videoID", "titles"."hashedVideoID", "titleVotes"."verification", "titles"."userID"
|
`SELECT "titles"."title", "titles"."original", "titleVotes"."votes", "titleVotes"."locked", "titleVotes"."shadowHidden", "titles"."UUID", "titles"."videoID", "titles"."hashedVideoID", "titleVotes"."verification", "titles"."userID"
|
||||||
FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID"
|
FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID"
|
||||||
WHERE "titles"."videoID" = ? AND "titles"."service" = ? AND "titleVotes"."votes" > -2`,
|
WHERE "titles"."videoID" = ? AND "titles"."service" = ? AND "titleVotes"."votes" > -2
|
||||||
|
GROUP BY "titles"."userID"
|
||||||
|
ORDER BY "titleVotes"."votes", "titles"."timeSubmitted" DESC`,
|
||||||
[videoID, service],
|
[videoID, service],
|
||||||
{ useReplica: true }
|
{ useReplica: true }
|
||||||
) as Promise<TitleDBResult[]>;
|
) as Promise<TitleDBResult[]>;
|
||||||
@@ -35,7 +37,9 @@ export async function getVideoBranding(res: Response, videoID: VideoID, service:
|
|||||||
"all",
|
"all",
|
||||||
`SELECT "thumbnailTimestamps"."timestamp", "thumbnails"."original", "thumbnailVotes"."votes", "thumbnailVotes"."locked", "thumbnailVotes"."shadowHidden", "thumbnails"."UUID", "thumbnails"."videoID", "thumbnails"."hashedVideoID", "thumbnails"."userID"
|
`SELECT "thumbnailTimestamps"."timestamp", "thumbnails"."original", "thumbnailVotes"."votes", "thumbnailVotes"."locked", "thumbnailVotes"."shadowHidden", "thumbnails"."UUID", "thumbnails"."videoID", "thumbnails"."hashedVideoID", "thumbnails"."userID"
|
||||||
FROM "thumbnails" LEFT JOIN "thumbnailVotes" ON "thumbnails"."UUID" = "thumbnailVotes"."UUID" LEFT JOIN "thumbnailTimestamps" ON "thumbnails"."UUID" = "thumbnailTimestamps"."UUID"
|
FROM "thumbnails" LEFT JOIN "thumbnailVotes" ON "thumbnails"."UUID" = "thumbnailVotes"."UUID" LEFT JOIN "thumbnailTimestamps" ON "thumbnails"."UUID" = "thumbnailTimestamps"."UUID"
|
||||||
WHERE "thumbnails"."videoID" = ? AND "thumbnails"."service" = ? AND "thumbnailVotes"."votes" > -2`,
|
WHERE "thumbnails"."videoID" = ? AND "thumbnails"."service" = ? AND "thumbnailVotes"."votes" > -2
|
||||||
|
GROUP BY "thumbnails"."userID"
|
||||||
|
ORDER BY "thumbnailVotes"."votes", "thumbnails"."timeSubmitted" DESC`,
|
||||||
[videoID, service],
|
[videoID, service],
|
||||||
{ useReplica: true }
|
{ useReplica: true }
|
||||||
) as Promise<ThumbnailDBResult[]>;
|
) as Promise<ThumbnailDBResult[]>;
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ describe("getBranding", () => {
|
|||||||
db.prepare("run", titleQuery, [videoID1, "title1", 0, "userID1", Service.YouTube, videoID1Hash, 1, "UUID1"]),
|
db.prepare("run", titleQuery, [videoID1, "title1", 0, "userID1", Service.YouTube, videoID1Hash, 1, "UUID1"]),
|
||||||
db.prepare("run", titleQuery, [videoID1, "title2", 0, "userID2", Service.YouTube, videoID1Hash, 1, "UUID2"]),
|
db.prepare("run", titleQuery, [videoID1, "title2", 0, "userID2", Service.YouTube, videoID1Hash, 1, "UUID2"]),
|
||||||
db.prepare("run", titleQuery, [videoID1, "title3", 1, "userID3", Service.YouTube, videoID1Hash, 1, "UUID3"]),
|
db.prepare("run", titleQuery, [videoID1, "title3", 1, "userID3", Service.YouTube, videoID1Hash, 1, "UUID3"]),
|
||||||
|
// Will be ignored since it has the same userID, but less votes
|
||||||
|
db.prepare("run", titleQuery, [videoID1, "some badly written title", 0, "userID3", Service.YouTube, videoID1Hash, 1, "UUID4"]),
|
||||||
db.prepare("run", thumbnailQuery, [videoID1, 0, "userID1", Service.YouTube, videoID1Hash, 1, "UUID1T"]),
|
db.prepare("run", thumbnailQuery, [videoID1, 0, "userID1", Service.YouTube, videoID1Hash, 1, "UUID1T"]),
|
||||||
db.prepare("run", thumbnailQuery, [videoID1, 1, "userID2", Service.YouTube, videoID1Hash, 1, "UUID2T"]),
|
db.prepare("run", thumbnailQuery, [videoID1, 1, "userID2", Service.YouTube, videoID1Hash, 1, "UUID2T"]),
|
||||||
db.prepare("run", thumbnailQuery, [videoID1, 0, "userID3", Service.YouTube, videoID1Hash, 1, "UUID3T"]),
|
db.prepare("run", thumbnailQuery, [videoID1, 0, "userID3", Service.YouTube, videoID1Hash, 1, "UUID3T"]),
|
||||||
|
|||||||
Reference in New Issue
Block a user