Check deletedAt. (#1796)

This commit is contained in:
Brian Cao 2023-02-27 16:01:34 -08:00 committed by GitHub
parent 5657a64c77
commit 84430e38eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 52 deletions

View file

@ -1,7 +1,6 @@
import { Prisma, Website } from '@prisma/client';
import cache from 'lib/cache';
import prisma from 'lib/prisma';
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
export async function getWebsite(where: Prisma.WebsiteWhereUniqueInput): Promise<Website> {
return prisma.client.website.findUnique({
@ -69,17 +68,11 @@ export async function resetWebsite(
});
}
export async function deleteWebsite(websiteId: string) {
return runQuery({
[PRISMA]: () => deleteWebsiteRelationalQuery(websiteId),
[CLICKHOUSE]: () => deleteWebsiteClickhouseQuery(websiteId),
});
}
async function deleteWebsiteRelationalQuery(
export async function deleteWebsite(
websiteId,
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
const { client, transaction } = prisma;
const cloudMode = process.env.CLOUD_MODE;
return transaction([
client.websiteEvent.deleteMany({
@ -88,9 +81,16 @@ async function deleteWebsiteRelationalQuery(
client.session.deleteMany({
where: { websiteId },
}),
client.website.delete({
where: { id: websiteId },
}),
cloudMode
? prisma.client.website.update({
data: {
deletedAt: new Date(),
},
where: { id: websiteId },
})
: client.website.delete({
where: { id: websiteId },
}),
]).then(async data => {
if (cache.enabled) {
await cache.deleteWebsite(websiteId);
@ -99,12 +99,3 @@ async function deleteWebsiteRelationalQuery(
return data;
});
}
async function deleteWebsiteClickhouseQuery(websiteId): Promise<Website> {
return prisma.client.website.update({
data: {
deletedAt: new Date(),
},
where: { id: websiteId },
});
}