···1515 text: string;
1616 emoji: string;
1717 created_at: string;
1818+ handle?: string; // Optional handle field from the database
1819}
19202021// Type for the processed entry for the client
···8485 did,
8586 text,
8687 emoji,
8787- created_at
8888+ created_at,
8989+ handle
8890 `)
8991 .lt('created_at', cursorRecord.created_at) // Get entries older than cursor
9092 .order('created_at', { ascending: false })
···96989799 // Process and return older entries (skip caching)
98100 const processedEntries = await Promise.all((entries || []).map(async (entry: FlushingRecord) => {
101101+ // Get the DID
99102 const authorDid = entry.did;
100100- const authorHandle = await resolveDidToHandle(authorDid);
103103+104104+ // First check if we have a valid handle in the database record
105105+ // and it's not "unknown"
106106+ let authorHandle: string;
107107+ if (entry.handle && entry.handle !== 'unknown') {
108108+ // Use the handle from the database
109109+ authorHandle = entry.handle;
110110+ console.log(`Using handle from database for ${authorDid}: ${authorHandle}`);
111111+112112+ // Store in cache for future use
113113+ dbHandleCache.set(authorDid, authorHandle);
114114+ } else if (dbHandleCache.has(authorDid)) {
115115+ // Use cached handle from previous database entries
116116+ authorHandle = dbHandleCache.get(authorDid)!;
117117+ console.log(`Using cached DB handle for ${authorDid}: ${authorHandle}`);
118118+ } else {
119119+ // Resolve handle from DID
120120+ authorHandle = await resolveDidToHandle(authorDid);
121121+ console.log(`Resolved handle for ${authorDid}: ${authorHandle}`);
122122+ }
101123102124 if (containsBannedWords(entry.text)) {
103125 return null;
···152174 did,
153175 text,
154176 emoji,
155155- created_at
177177+ created_at,
178178+ handle
156179 `)
157180 .order('created_at', { ascending: false })
158181 .limit(MAX_ENTRIES);
···170193171194 // Transform the data to match our client-side model
172195 const processedEntries = await Promise.all((entries || []).map(async (entry: FlushingRecord) => {
173173- // Resolve handle from DID
196196+ // Get the DID
174197 const authorDid = entry.did;
175175- const authorHandle = await resolveDidToHandle(authorDid);
198198+199199+ // First check if we have a valid handle in the database record
200200+ // and it's not "unknown"
201201+ let authorHandle: string;
202202+ if (entry.handle && entry.handle !== 'unknown') {
203203+ // Use the handle from the database
204204+ authorHandle = entry.handle;
205205+ console.log(`Using handle from database for ${authorDid}: ${authorHandle}`);
206206+207207+ // Store in cache for future use
208208+ dbHandleCache.set(authorDid, authorHandle);
209209+ } else if (dbHandleCache.has(authorDid)) {
210210+ // Use cached handle from previous database entries
211211+ authorHandle = dbHandleCache.get(authorDid)!;
212212+ console.log(`Using cached DB handle for ${authorDid}: ${authorHandle}`);
213213+ } else {
214214+ // Resolve handle from DID
215215+ authorHandle = await resolveDidToHandle(authorDid);
216216+ console.log(`Resolved handle for ${authorDid}: ${authorHandle}`);
217217+ }
176218177219 // Skip entries with banned content
178220 if (containsBannedWords(entry.text)) {
···265307266308// DID resolution cache
267309const didResolutionCache = new Map<string, string>();
310310+311311+// Handle column cache - maps DID to handle stored in the database
312312+// This allows us to use existing handle values from the DB instead of resolving every time
313313+const dbHandleCache = new Map<string, string>();
268314269315// Timeout promise to prevent hanging on API calls
270316function timeout(ms: number): Promise<never> {
···392438393439 // If we get here, all resolution methods failed
394440 console.log(`All resolution methods failed for ${did}, using shortened DID: ${shortDid}`);
441441+442442+ // Create a user-friendly version of the DID
443443+ // Format: "user.{first6chars}"
444444+ const userFriendlyDid = did.startsWith('did:plc:') ?
445445+ `user.${did.substring(8, 14)}` :
446446+ `user.${did.substring(0, 6)}`;
447447+395448 // Cache the fallback result too
396396- didResolutionCache.set(did, shortDid);
397397- return shortDid;
449449+ didResolutionCache.set(did, userFriendlyDid);
450450+ return userFriendlyDid;
398451 } catch (error) {
399452 console.error(`Failed to resolve handle for DID ${did}:`, error);
400400- // Last resort fallback is the shortened DID
401401- const shortDid = did.startsWith('did:plc:') ?
402402- `${did.substring(0, 13)}...` :
403403- `${did.substring(0, 10)}...`;
404404- return shortDid;
453453+ // Last resort fallback is a user-friendly version of the DID
454454+ const userFriendlyDid = did.startsWith('did:plc:') ?
455455+ `user.${did.substring(8, 14)}` :
456456+ `user.${did.substring(0, 6)}`;
457457+ return userFriendlyDid;
405458 }
406459}
+2-2
app/src/app/page.tsx
···4242 // Fetch the latest entries when the component mounts
4343 fetchLatestEntries(true); // Force refresh on initial load
44444545- // Set up periodic refresh every 60 seconds
4545+ // Set up periodic refresh every 20 seconds
4646 const refreshInterval = setInterval(() => {
4747 console.log('Auto-refreshing feed...');
4848 fetchLatestEntries(true);
4949- }, 60000);
4949+ }, 20000);
50505151 // Clean up interval on unmount
5252 return () => clearInterval(refreshInterval);