mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-24 11:39:22 -05:00
chore: add react cache to improve render performance (#2867)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import "server-only";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { cache as reactCache } from "react";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
import { cache } from "../cache";
|
||||
@@ -7,38 +8,42 @@ import { organizationCache } from "../organization/cache";
|
||||
import { userCache } from "../user/cache";
|
||||
|
||||
// Function to check if there are any users in the database
|
||||
export const getIsFreshInstance = (): Promise<boolean> =>
|
||||
cache(
|
||||
async () => {
|
||||
try {
|
||||
const userCount = await prisma.user.count();
|
||||
if (userCount === 0) return true;
|
||||
else return false;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
export const getIsFreshInstance = reactCache(
|
||||
(): Promise<boolean> =>
|
||||
cache(
|
||||
async () => {
|
||||
try {
|
||||
const userCount = await prisma.user.count();
|
||||
if (userCount === 0) return true;
|
||||
else return false;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
["getIsFreshInstance"],
|
||||
{ tags: [userCache.tag.byCount()] }
|
||||
)();
|
||||
},
|
||||
["getIsFreshInstance"],
|
||||
{ tags: [userCache.tag.byCount()] }
|
||||
)()
|
||||
);
|
||||
|
||||
// Function to check if there are any organizations in the database
|
||||
export const gethasNoOrganizations = (): Promise<boolean> =>
|
||||
cache(
|
||||
async () => {
|
||||
try {
|
||||
const organizationCount = await prisma.organization.count();
|
||||
return organizationCount === 0;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
export const gethasNoOrganizations = reactCache(
|
||||
(): Promise<boolean> =>
|
||||
cache(
|
||||
async () => {
|
||||
try {
|
||||
const organizationCount = await prisma.organization.count();
|
||||
return organizationCount === 0;
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
throw new DatabaseError(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
["gethasNoOrganizations"],
|
||||
{ tags: [organizationCache.tag.byCount()] }
|
||||
)();
|
||||
},
|
||||
["gethasNoOrganizations"],
|
||||
{ tags: [organizationCache.tag.byCount()] }
|
||||
)()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user