add db call as fallback

This commit is contained in:
Brian Cao 2022-08-29 13:04:58 -07:00
parent 9ddbd12060
commit b6cd9f305b
10 changed files with 71 additions and 40 deletions

View file

@ -14,7 +14,7 @@ export async function createWebsite(user_id, data) {
},
})
.then(async res => {
if (process.env.REDIS_URL && res) {
if (redis.client && res) {
await redis.set(`website:${res.website_uuid}`, Number(res.website_id));
}

View file

@ -1,9 +1,12 @@
import prisma from 'lib/prisma';
import redis from 'lib/redis';
import redis, { DELETED } from 'lib/redis';
import { getWebsiteById } from 'queries';
export async function deleteWebsite(website_id) {
const { client, transaction } = prisma;
const { website_uuid } = await getWebsiteById(website_id);
return transaction([
client.pageview.deleteMany({
where: { session: { website: { website_id } } },
@ -21,8 +24,10 @@ export async function deleteWebsite(website_id) {
where: { website_id },
}),
]).then(async res => {
if (process.env.REDIS_URL) {
await redis.client.del(`website:${res.website_uuid}`);
if (redis.client) {
await redis.client.set(`website:${website_uuid}`, DELETED);
}
return res;
});
}

View file

@ -9,7 +9,7 @@ export async function getWebsiteByUuid(website_uuid) {
},
})
.then(async res => {
if (process.env.REDIS_URL && res) {
if (redis.client && res) {
await redis.client.set(`website:${res.website_uuid}`, 1);
}

View file

@ -18,7 +18,7 @@ export async function resetWebsite(website_id) {
where: { website: { website_id } },
}),
]).then(async res => {
if (process.env.REDIS_URL) {
if (redis.client) {
await redis.del(`website:${res.website_uuid}`);
}
});