···
const data: ConstellationBacklinksResponse = await response.json();
console.log('Constellation response:', data);
···
console.warn('No records found in response');
326
-
// fetch each record from the repository
327
-
const signatures: GuestbookSignature[] = [];
329
-
for (const record of data.records) {
326
+
// Fetch all records in parallel
327
+
const recordPromises = data.records.map(async (record) => {
const recordUrl = new URL('/xrpc/com.atproto.repo.getRecord', 'https://slingshot.wisp.place');
recordUrl.searchParams.set('repo', record.did);
recordUrl.searchParams.set('collection', record.collection);
recordUrl.searchParams.set('rkey', record.rkey);
const recordResponse = await fetch(recordUrl.toString());
if (!recordResponse.ok) {
console.warn(`Failed to fetch record ${record.did}/${record.collection}/${record.rkey}`);
const recordData = await recordResponse.json();
···
typeof recordData.value.message === 'string' &&
typeof recordData.value.createdAt === 'string'
351
-
// Fetch the handle for this author
352
-
let authorHandle: string | undefined;
354
-
const profileResponse = await fetch(
355
-
`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${record.did}`
357
-
if (profileResponse.ok) {
358
-
const profileData = await profileResponse.json();
359
-
authorHandle = profileData.handle;
362
-
console.warn(`Failed to fetch handle for ${record.did}:`, err);
370
-
authorHandle: authorHandle,
354
+
authorHandle: undefined,
355
+
} as GuestbookSignature;
console.warn(`Error fetching record ${record.did}/${record.collection}/${record.rkey}:`, err);
378
-
// sort by creation time, newest first
379
-
this.signatures = signatures.sort((a, b) => {
363
+
const results = await Promise.all(recordPromises);
364
+
const validSignatures = results.filter((sig): sig is GuestbookSignature => sig !== null);
366
+
// Sort once after collecting all signatures
367
+
validSignatures.sort((a, b) => {
return new Date(b.value.createdAt).getTime() - new Date(a.value.createdAt).getTime();
371
+
this.signatures = validSignatures;
375
+
// Batch fetch profiles asynchronously
376
+
if (validSignatures.length > 0) {
377
+
const uniqueDids = Array.from(new Set(validSignatures.map(sig => sig.author)));
379
+
// Batch fetch profiles up to 25 at a time (API limit)
380
+
const profilePromises = [];
381
+
for (let i = 0; i < uniqueDids.length; i += 25) {
382
+
const batch = uniqueDids.slice(i, i + 25);
384
+
const profileUrl = new URL('/xrpc/app.bsky.actor.getProfiles', 'https://public.api.bsky.app');
385
+
batch.forEach(d => profileUrl.searchParams.append('actors', d));
387
+
profilePromises.push(
388
+
fetch(profileUrl.toString())
389
+
.then(profileResponse => profileResponse.ok ? profileResponse.json() : null)
390
+
.then(profilesData => {
391
+
if (profilesData?.profiles && Array.isArray(profilesData.profiles)) {
392
+
const handles = new Map<string, string>();
393
+
profilesData.profiles.forEach((profile: any) => {
394
+
if (profile.handle) {
395
+
handles.set(profile.did, profile.handle);
400
+
return new Map<string, string>();
403
+
console.warn('Failed to fetch profile batch:', err);
404
+
return new Map<string, string>();
409
+
// Wait for all profile batches, then update once
410
+
const handleMaps = await Promise.all(profilePromises);
411
+
const allHandles = new Map<string, string>();
412
+
handleMaps.forEach(map => {
413
+
map.forEach((handle, did) => allHandles.set(did, handle));
416
+
if (allHandles.size > 0) {
417
+
this.signatures = this.signatures.map(sig => {
418
+
const handle = allHandles.get(sig.author);
419
+
return handle ? { ...sig, authorHandle: handle } : sig;
421
+
this.updateContent();
console.error('Error fetching signatures:', error);
this.error = error instanceof Error ? error.message : 'Unknown error occurred';
···
private shortenDid(did: string): string {
406
-
if (did.startsWith('did:plc:')) {
407
-
return `${did.slice(0, 16)}...${did.slice(-4)}`;
445
+
if (did.startsWith('did:')) {
446
+
const afterPrefix = did.indexOf(':', 4);
447
+
if (afterPrefix !== -1) {
448
+
return `${did.slice(0, afterPrefix + 9)}...`;