diff --git a/packages/lib/person/auth.ts b/packages/lib/person/auth.ts index 20d0015aea..a642a10615 100644 --- a/packages/lib/person/auth.ts +++ b/packages/lib/person/auth.ts @@ -25,6 +25,6 @@ export const canUserAccessPerson = async (userId: string, personId: string): Pro [`canUserAccessPerson-${userId}-people-${personId}`], { revalidate: SERVICES_REVALIDATION_INTERVAL, - tags: [personCache.tag.byId(personId), personCache.tag.byUserId(userId)], + tags: [personCache.tag.byId(personId)], } )(); diff --git a/packages/lib/person/cache.ts b/packages/lib/person/cache.ts index 69e8b15b95..4e9b6932f8 100644 --- a/packages/lib/person/cache.ts +++ b/packages/lib/person/cache.ts @@ -14,11 +14,8 @@ export const personCache = { byEnvironmentId(environmentId: string): string { return `environments-${environmentId}-people`; }, - byUserId(userId: string): string { - return `users-${userId}-people`; - }, byEnvironmentIdAndUserId(environmentId: string, userId: string): string { - return `environments-${environmentId}-users-${userId}-people`; + return `environments-${environmentId}-personByUserId-${userId}`; }, }, revalidate({ id, environmentId, userId }: RevalidateProps): void { @@ -26,16 +23,12 @@ export const personCache = { revalidateTag(this.tag.byId(id)); } - if (environmentId) { - revalidateTag(this.tag.byEnvironmentId(environmentId)); - } - - if (userId) { - revalidateTag(this.tag.byUserId(userId)); - } - if (environmentId && userId) { revalidateTag(this.tag.byEnvironmentIdAndUserId(environmentId, userId)); } + + if (environmentId) { + revalidateTag(this.tag.byEnvironmentId(environmentId)); + } }, }; diff --git a/packages/lib/person/service.ts b/packages/lib/person/service.ts index 9f23ada0b6..8290636cbb 100644 --- a/packages/lib/person/service.ts +++ b/packages/lib/person/service.ts @@ -291,10 +291,10 @@ export const updatePerson = async (personId: string, personInput: TPersonUpdateI } }; -export const getPersonByUserId = async (environmentId: string, userId: string): Promise => { - const personPrisma = await unstable_cache( +export const getPersonByUserId = async (environmentId: string, userId: string): Promise => + await unstable_cache( async () => { - validateInputs([userId, ZString], [environmentId, ZId]); + validateInputs([environmentId, ZId], [userId, ZString]); // check if userId exists as a column const personWithUserId = await prisma.person.findFirst({ @@ -306,7 +306,7 @@ export const getPersonByUserId = async (environmentId: string, userId: string): }); if (personWithUserId) { - return personWithUserId; + return transformPrismaPerson(personWithUserId); } // Check if a person with the userId attribute exists @@ -352,23 +352,14 @@ export const getPersonByUserId = async (environmentId: string, userId: string): userId, }); - return personWithUserIdAttribute; + return transformPrismaPerson(personWithUserIdAttribute); }, - [`getPersonByUserId-${userId}-${environmentId}`], + [`getPersonByUserId-${environmentId}-${userId}`], { - tags: [ - personCache.tag.byEnvironmentIdAndUserId(environmentId, userId), - personCache.tag.byUserId(userId), // fix for caching issue on vercel - personCache.tag.byEnvironmentId(environmentId), // fix for caching issue on vercel - ], + tags: [personCache.tag.byEnvironmentIdAndUserId(environmentId, userId)], revalidate: SERVICES_REVALIDATION_INTERVAL, } )(); - if (!personPrisma) { - return null; - } - return transformPrismaPerson(personPrisma); -}; export const updatePersonAttribute = async ( personId: string,