This commit is contained in:
ld3zian 2025-03-28 20:37:56 -07:00
parent 984dc04ee8
commit 44d74806d7

View file

@ -495,21 +495,35 @@ export async function getFeedMapping(
} }
} }
// If jsonString is still null/empty after checks, the key wasn't found
if (!jsonString) { if (!jsonString) {
console.log(`[getFeedMapping] Key ${feedId} (and compressed variant) not found on any checked instance.`); console.log(`[getFeedMapping] Key ${feedId} (and compressed variant) not found on any checked instance.`);
return null; return null;
} }
// Reset expiration on access (only if found via regular key initially or synced from replica) // --- Reset TTL for the regular key now that we have its value ---
console.log(`[getFeedMapping] Resetting TTL for regular key ${regularKey} on ${clientName}`); console.log(`[getFeedMapping] Resetting TTL for regular key ${regularKey} on ${clientName}`);
// Use try-catch for the expire call to prevent it from stopping data return if expire fails
try {
// Reset TTL on the client instance we initially connected to
await client.expire(regularKey, DEFAULT_CACHE_TTL); await client.expire(regularKey, DEFAULT_CACHE_TTL);
} catch (expireError) {
console.warn(`[getFeedMapping] Failed to reset TTL for regular key ${regularKey} on ${clientName}:`, expireError);
}
// --- End TTL Reset ---
// Parse the result // Parse the result (jsonString has the data from either initial client or replica)
const data = JSON.parse(jsonString as string); try {
const data = JSON.parse(jsonString); // Removed 'as string' for potentially better type safety if needed
return { return {
slugs: data.slugs, slugs: data.slugs,
lang: data.lang lang: data.lang
}; };
} catch (parseError) {
console.error(`[getFeedMapping] CRITICAL ERROR parsing feed mapping JSON for ${feedId}:`, parseError, `JSON String: ${jsonString}`);
return null; // Return null if parsing fails
}
} catch (error) { } catch (error) {
console.error(`[getFeedMapping] CRITICAL ERROR retrieving feed mapping for ${feedId}:`, error); console.error(`[getFeedMapping] CRITICAL ERROR retrieving feed mapping for ${feedId}:`, error);
return null; return null;