Add status handling in profile extraction and caching logic

This commit is contained in:
MartinBraquet
2026-04-08 16:33:02 +02:00
parent 3bd0241dec
commit f3882f91b7
2 changed files with 7 additions and 6 deletions

View File

@@ -209,10 +209,7 @@ async function getCachedResult(cacheKey: string): Promise<Partial<ProfileWithout
}
}
async function setCachedResult(
cacheKey: string,
result: Partial<ProfileWithoutUser>,
): Promise<void> {
async function setCachedResult(cacheKey: string, result: any): Promise<void> {
if (!USE_CACHE) return
try {
await fs.mkdir(CACHE_DIR, {recursive: true})
@@ -285,9 +282,10 @@ async function processAndCache(
if (bio) {
profile.bio = bio
}
await setCachedResult(cacheKey, profile)
await setCachedResult(cacheKey, {profile, status: 'success'})
} catch (error) {
log('Async LLM processing failed', {cacheKey, error})
await setCachedResult(cacheKey, {profile: {}, status: 'error'})
} finally {
await clearProcessing(cacheKey)
}
@@ -589,7 +587,7 @@ export const llmExtractProfileEndpoint: APIHandler<'llm-extract-profile'> = asyn
const cached = await getCachedResult(cacheKey)
if (cached) {
log('Returning cached profile', {cacheKey: cacheKey.substring(0, 8)})
return {profile: cached, status: 'success'}
return cached as {profile: Partial<ProfileWithoutUser>; status: 'success' | 'error' | 'pending'}
}
// Check if already processing

View File

@@ -131,6 +131,9 @@ export const OptionalProfileUserForm = (props: {
}
extractedProfile = response.profile
}
if (status !== 'success') {
throw new Error('Failed to extract profile')
}
extractedProfile = removeNullOrUndefinedProps(extractedProfile)
for (const data of Object.entries(extractedProfile)) {
const key = data[0] as keyof ProfileWithoutUser