mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 08:37:13 +01:00
add redis calls to website delete/reset
This commit is contained in:
parent
90bd72cf98
commit
f259130202
1 changed files with 17 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { Prisma, Website } from '@prisma/client';
|
import { Prisma, Website } from '@prisma/client';
|
||||||
|
import redis from '@umami/redis-client';
|
||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
import { PageResult, PageParams } from 'lib/types';
|
import { PageResult, PageParams } from 'lib/types';
|
||||||
import WebsiteFindManyArgs = Prisma.WebsiteFindManyArgs;
|
import WebsiteFindManyArgs = Prisma.WebsiteFindManyArgs;
|
||||||
|
|
@ -122,6 +123,7 @@ export async function resetWebsite(
|
||||||
websiteId: string,
|
websiteId: string,
|
||||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||||
const { client, transaction } = prisma;
|
const { client, transaction } = prisma;
|
||||||
|
const cloudMode = !!process.env.cloudMode;
|
||||||
|
|
||||||
return transaction([
|
return transaction([
|
||||||
client.eventData.deleteMany({
|
client.eventData.deleteMany({
|
||||||
|
|
@ -139,14 +141,20 @@ export async function resetWebsite(
|
||||||
resetAt: new Date(),
|
resetAt: new Date(),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
]);
|
]).then(async data => {
|
||||||
|
if (cloudMode) {
|
||||||
|
await redis.client.set(`website:${websiteId}`, data[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteWebsite(
|
export async function deleteWebsite(
|
||||||
websiteId: string,
|
websiteId: string,
|
||||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||||
const { client, transaction } = prisma;
|
const { client, transaction } = prisma;
|
||||||
const cloudMode = process.env.CLOUD_MODE;
|
const cloudMode = !!process.env.CLOUD_MODE;
|
||||||
|
|
||||||
return transaction([
|
return transaction([
|
||||||
client.eventData.deleteMany({
|
client.eventData.deleteMany({
|
||||||
|
|
@ -173,5 +181,11 @@ export async function deleteWebsite(
|
||||||
: client.website.delete({
|
: client.website.delete({
|
||||||
where: { id: websiteId },
|
where: { id: websiteId },
|
||||||
}),
|
}),
|
||||||
]);
|
]).then(async data => {
|
||||||
|
if (cloudMode) {
|
||||||
|
await redis.client.del(`website:${websiteId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue