+27
src/lib/atproto/atproto-browser.ts
+27
src/lib/atproto/atproto-browser.ts
···
140
140
}
141
141
}
142
142
143
+
// Get all records from a collection using pagination
144
+
async getAllCollectionRecords(
145
+
identifier: string,
146
+
collection: string,
147
+
maxTotal: number = 1000
148
+
): Promise<AtprotoRecord[]> {
149
+
const results: AtprotoRecord[] = [];
150
+
let cursor: string | undefined = undefined;
151
+
152
+
try {
153
+
while (true) {
154
+
const page = await this.getCollectionRecords(identifier, collection, 100, cursor);
155
+
if (!page) break;
156
+
157
+
results.push(...page.records);
158
+
159
+
if (!page.cursor) break;
160
+
if (results.length >= maxTotal) break;
161
+
cursor = page.cursor;
162
+
}
163
+
} catch (error) {
164
+
console.error(`Error paginating collection ${collection}:`, error);
165
+
}
166
+
167
+
return results.slice(0, maxTotal);
168
+
}
169
+
143
170
// Get all collections for a repository
144
171
async getAllCollections(identifier: string): Promise<string[]> {
145
172
try {
+5
-10
src/lib/services/grain-gallery-service.ts
+5
-10
src/lib/services/grain-gallery-service.ts
···
221
221
}
222
222
223
223
// Fetch the four relevant collections
224
-
const [galleries, items, photos, exifs] = await Promise.all([
225
-
this.browser.getCollectionRecords(identifier, 'social.grain.gallery', 100),
226
-
this.browser.getCollectionRecords(identifier, 'social.grain.gallery.item', 100),
227
-
this.browser.getCollectionRecords(identifier, 'social.grain.photo', 100),
228
-
this.browser.getCollectionRecords(identifier, 'social.grain.photo.exif', 100),
224
+
const [galleryRecords, itemRecords, photoRecords, exifRecords] = await Promise.all([
225
+
this.browser.getAllCollectionRecords(identifier, 'social.grain.gallery', 500),
226
+
this.browser.getAllCollectionRecords(identifier, 'social.grain.gallery.item', 5000),
227
+
this.browser.getAllCollectionRecords(identifier, 'social.grain.photo', 5000),
228
+
this.browser.getAllCollectionRecords(identifier, 'social.grain.photo.exif', 5000),
229
229
]);
230
-
231
-
const galleryRecords = galleries?.records ?? [];
232
-
const itemRecords = items?.records ?? [];
233
-
const photoRecords = photos?.records ?? [];
234
-
const exifRecords = exifs?.records ?? [];
235
230
236
231
// Build maps for fast lookup
237
232
const photosByUri = new Map<string, AtprotoRecord>();