implement cloud mode logic

This commit is contained in:
Francis Cao 2023-02-09 10:13:50 -08:00
parent 54d5af5cbb
commit 9f8ea060b6
3 changed files with 28 additions and 35 deletions

View File

@ -16,7 +16,7 @@ export default async (req: NextApiRequest, res: NextApiResponse<ConfigResponse>)
trackerScriptName: process.env.TRACKER_SCRIPT_NAME, trackerScriptName: process.env.TRACKER_SCRIPT_NAME,
updatesDisabled: !!process.env.DISABLE_UPDATES, updatesDisabled: !!process.env.DISABLE_UPDATES,
telemetryDisabled: !!process.env.DISABLE_TELEMETRY, telemetryDisabled: !!process.env.DISABLE_TELEMETRY,
adminDisabled: !!process.env.DISABLE_ADMIN, adminDisabled: !!process.env.CLOUD_MODE,
}); });
} }

View File

@ -16,7 +16,7 @@ export default function LoginPage({ pageDisabled }) {
export async function getServerSideProps() { export async function getServerSideProps() {
return { return {
props: { props: {
pageDisabled: !!process.env.DISABLE_LOGIN, pageDisabled: !!process.env.CLOUD_MODE,
}, },
}; };
} }

View File

@ -69,42 +69,35 @@ export async function resetWebsite(
}); });
} }
export async function deleteWebsite(websiteId: string) { export async function deleteWebsite(
return runQuery({ websiteId: string,
[PRISMA]: () => deleteWebsiteRelationalQuery(websiteId),
[CLICKHOUSE]: () => deleteWebsiteClickhouseQuery(websiteId),
});
}
async function deleteWebsiteRelationalQuery(
websiteId,
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> { ): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
const { client, transaction } = prisma; const { client, transaction } = prisma;
return transaction([ if (process.env.CLOUD_MODE) {
client.websiteEvent.deleteMany({ return prisma.client.website.update({
where: { websiteId }, data: {
}), deletedAt: new Date(),
client.session.deleteMany({ },
where: { websiteId },
}),
client.website.delete({
where: { id: websiteId }, where: { id: websiteId },
}), });
]).then(async data => { } else {
if (cache.enabled) { return transaction([
await cache.deleteWebsite(websiteId); client.websiteEvent.deleteMany({
} where: { websiteId },
}),
client.session.deleteMany({
where: { websiteId },
}),
client.website.delete({
where: { id: websiteId },
}),
]).then(async data => {
if (cache.enabled) {
await cache.deleteWebsite(websiteId);
}
return data; return data;
}); });
} }
async function deleteWebsiteClickhouseQuery(websiteId): Promise<Website> {
return prisma.client.website.update({
data: {
deletedAt: new Date(),
},
where: { id: websiteId },
});
} }