mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 23:27:12 +01:00
Check deletedAt. (#1796)
This commit is contained in:
parent
5657a64c77
commit
84430e38eb
4 changed files with 47 additions and 52 deletions
|
|
@ -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 },
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue