Add more things to read from replica

This commit is contained in:
Ajay
2022-07-20 01:21:13 -04:00
parent f1ed8eff84
commit dd47f87616
7 changed files with 15 additions and 14 deletions

View File

@@ -5,7 +5,7 @@ import { userFeatureKey } from "./redisKeys";
export async function hasFeature(userID: HashedUserID, feature: Feature): Promise<boolean> {
return await QueryCacher.get(async () => {
const result = await db.prepare("get", 'SELECT "feature" from "userFeatures" WHERE "userID" = ? AND "feature" = ?', [userID, feature]);
const result = await db.prepare("get", 'SELECT "feature" from "userFeatures" WHERE "userID" = ? AND "feature" = ?', [userID, feature], { useReplica: true });
return !!result;
}, userFeatureKey(userID, feature));
}

View File

@@ -2,5 +2,6 @@ import { db } from "../databases/databases";
import { HashedUserID } from "../types/user.model";
export async function isUserVIP(userID: HashedUserID): Promise<boolean> {
return (await db.prepare("get", `SELECT count(*) as "userCount" FROM "vipUsers" WHERE "userID" = ? LIMIT 1`, [userID]))?.userCount > 0;
return (await db.prepare("get", `SELECT count(*) as "userCount" FROM "vipUsers" WHERE "userID" = ? LIMIT 1`,
[userID], { useReplica: true }))?.userCount > 0;
}

View File

@@ -40,7 +40,7 @@ export async function getReputation(userID: UserID): Promise<number> {
SELECT * FROM "lockCategories" as l
WHERE l."videoID" = "a"."videoID" AND l."service" = "a"."service" AND l."category" = "a"."category" LIMIT 1)
THEN 1 ELSE 0 END) AS "mostUpvotedInLockedVideoSum"
FROM "sponsorTimes" as "a" WHERE "userID" = ?`, [userID, weekAgo, pastDate, userID]) as Promise<ReputationDBResult>;
FROM "sponsorTimes" as "a" WHERE "userID" = ?`, [userID, weekAgo, pastDate, userID], { useReplica: true }) as Promise<ReputationDBResult>;
const result = await QueryCacher.get(fetchFromDB, reputationKey(userID));