a tool for shared writing and social publishing

cache profile data

+11 -8
+11 -8
app/(home-pages)/p/[didOrHandle]/layout.tsx
··· 9 9 import { Agent } from "@atproto/api"; 10 10 import { get_profile_data } from "app/api/rpc/[command]/get_profile_data"; 11 11 import { Metadata } from "next"; 12 + import { cache } from "react"; 13 + 14 + // Cache the profile data call to prevent concurrent OAuth restores 15 + const getCachedProfileData = cache(async (did: string) => { 16 + return get_profile_data.handler( 17 + { didOrHandle: did }, 18 + { supabase: supabaseServerClient }, 19 + ); 20 + }); 12 21 13 22 export async function generateMetadata(props: { 14 23 params: Promise<{ didOrHandle: string }>; ··· 23 32 did = resolved; 24 33 } 25 34 26 - let profileData = await get_profile_data.handler( 27 - { didOrHandle: did }, 28 - { supabase: supabaseServerClient }, 29 - ); 35 + let profileData = await getCachedProfileData(did); 30 36 let { profile } = profileData.result; 31 37 32 38 if (!profile) return { title: "Profile - Leaflet" }; ··· 66 72 } 67 73 did = resolved; 68 74 } 69 - let profileData = await get_profile_data.handler( 70 - { didOrHandle: did }, 71 - { supabase: supabaseServerClient }, 72 - ); 75 + let profileData = await getCachedProfileData(did); 73 76 let { publications, profile } = profileData.result; 74 77 75 78 if (!profile) return null;