Skip to content

Commit

Permalink
feat(thumbnailVotes): impl updatedAt
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanWasTaken committed Aug 19, 2024
1 parent ee353bd commit 277ea72
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions DatabaseSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@
| shadowHidden | INTEGER | not null, default 0 |
| downvotes | INTEGER | default 0 |
| removed | INTEGER | default 0 |
| createdAt | INTEGER | not null |
| updatedAt | INTEGER | not null |

| constraint | field |
| -- | :--: |
Expand Down
4 changes: 4 additions & 0 deletions databases/_upgrade_sponsorTimes_41.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ ALTER TABLE "lockCategories" ADD "updatedAt" INTEGER NOT NULL;
ALTER TABLE "titleVotes" ADD "createdAt" INTEGER NOT NULL;
ALTER TABLE "titleVotes" ADD "updatedAt" INTEGER NOT NULL;

-- thumbnailVotes
ALTER TABLE "thumbnailVotes" ADD "createdAt" INTEGER NOT NULL;
ALTER TABLE "thumbnailVotes" ADD "updatedAt" INTEGER NOT NULL;

UPDATE "config" SET value = 41 WHERE key = 'version';

COMMIT;
6 changes: 3 additions & 3 deletions src/routes/postBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export async function postBranding(req: Request, res: Response) {
await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`,
[videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]);

await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, ?)`,
[UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0]);
await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, 0, ?, ?, ?, ?)`,
[UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, now, now]);

if (!thumbnail.original) {
await db.prepare("run", `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`,
Expand All @@ -156,7 +156,7 @@ export async function postBranding(req: Request, res: Response) {

if (isVip && !downvote && shouldLock) {
// unlock all other titles
await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0 FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]);
await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [now, UUID, videoID]);
}
}
})()]);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/shadowBanUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ async function unHideSubmissionsByUser(categories: string[], deArrowTypes: DeArr
}

if (deArrowTypes.includes("thumbnail")) {
await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "shadowHidden" = ${type} FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`,
[userID]);
await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "shadowHidden" = ${type}, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`,
[currentTime, userID]);
}

(await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" WHERE "userID" = ?`, [userID]))
Expand Down

0 comments on commit 277ea72

Please sign in to comment.