···
const fetchedEntries: GuestbookEntry[] = []
64
+
const recordMap = new Map<string, any>()
65
+
const authorDids: string[] = []
67
+
// First pass: fetch all records and collect author DIDs
for (const record of data.records as ConstellationRecord[]) {
const recordUrl = new URL('/xrpc/com.atproto.repo.getRecord', 'https://slingshot.wisp.place')
···
recordData.value.$type === 'pet.nkp.guestbook.sign' &&
typeof recordData.value.message === 'string'
82
-
let authorHandle: string | undefined
84
-
const profileResponse = await fetch(
85
-
`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${record.did}`
87
-
if (profileResponse.ok) {
88
-
const profileData = await profileResponse.json()
89
-
authorHandle = profileData.handle
85
+
recordMap.set(record.did, recordData)
86
+
authorDids.push(record.did)
93
-
fetchedEntries.push({
94
-
uri: recordData.uri,
97
-
message: recordData.value.message,
98
-
createdAt: recordData.value.createdAt,
91
+
// Second pass: batch fetch all profiles at once
92
+
const authorHandles = new Map<string, string>()
93
+
if (authorDids.length > 0) {
95
+
// Batch fetch profiles up to 25 at a time (API limit)
96
+
for (let i = 0; i < authorDids.length; i += 25) {
97
+
const batch = authorDids.slice(i, i + 25)
98
+
const profileUrl = new URL('/xrpc/app.bsky.actor.getProfiles', 'https://public.api.bsky.app')
99
+
batch.forEach(did => profileUrl.searchParams.append('actors', did))
101
+
const profileResponse = await fetch(profileUrl.toString())
102
+
if (profileResponse.ok) {
103
+
const profilesData = await profileResponse.json()
104
+
if (profilesData.profiles && Array.isArray(profilesData.profiles)) {
105
+
profilesData.profiles.forEach((profile: any) => {
106
+
if (profile.handle) {
107
+
authorHandles.set(profile.did, profile.handle)
116
+
// Third pass: create entries with fetched profile data
117
+
for (const [did, recordData] of recordMap) {
118
+
const authorHandle = authorHandles.get(did)
119
+
fetchedEntries.push({
120
+
uri: recordData.uri,
123
+
message: recordData.value.message,
124
+
createdAt: recordData.value.createdAt,
// Sort by date, newest first