@@ -4,6 +4,7 @@ import MonkeyError, {
44 isFirebaseError ,
55} from "../../utils/error" ;
66import { MonkeyResponse } from "../../utils/monkey-response" ;
7+ import { getCached , setCached , invalidateUserCache } from "../../utils/cache" ;
78import * as DiscordUtils from "../../utils/discord" ;
89import {
910 buildAgentLog ,
@@ -914,6 +915,10 @@ export async function getProfile(
914915) : Promise < GetProfileResponse > {
915916 const { uidOrName } = req . params ;
916917
918+ const cacheKey = `user:profile:${ uidOrName } ` ;
919+ const cached = await getCached < GetProfileResponse > ( cacheKey ) ;
920+ if ( cached !== null ) return cached ;
921+
917922 const user = req . query . isUid
918923 ? await UserDAL . getUser ( uidOrName , "get user profile" )
919924 : await UserDAL . getUserByName ( uidOrName , "get user profile" ) ;
@@ -987,7 +992,11 @@ export async function getProfile(
987992 } ;
988993
989994 if ( banned ) {
990- return new MonkeyResponse ( "Profile retrived: banned user" , baseProfile ) ;
995+ await setCached (
996+ cacheKey ,
997+ new MonkeyResponse ( "Profile retrieved: banned user" , baseProfile ) ,
998+ ) ;
999+ return new MonkeyResponse ( "Profile retrieved: banned user" , baseProfile ) ;
9911000 }
9921001
9931002 const allTimeLbs = await getAllTimeLbs ( user . uid ) ;
@@ -1005,6 +1014,10 @@ export async function getProfile(
10051014 } else {
10061015 delete profileData . testActivity ;
10071016 }
1017+ await setCached (
1018+ cacheKey ,
1019+ new MonkeyResponse ( "Profile retrieved" , profileData ) ,
1020+ ) ;
10081021 return new MonkeyResponse ( "Profile retrieved" , profileData ) ;
10091022}
10101023
@@ -1050,6 +1063,7 @@ export async function updateProfile(
10501063 } ;
10511064
10521065 await UserDAL . updateProfile ( uid , profileDetailsUpdates , user . inventory ) ;
1066+ await invalidateUserCache ( uid ) ;
10531067
10541068 return new MonkeyResponse ( "Profile updated" , profileDetailsUpdates ) ;
10551069}
0 commit comments