···
205
205
206
206
if (existing) {
207
207
if (existing.sources.includes(source)) {
208
208
-
// Already indexed for this source — flush updates and stop
208
208
+
// Already indexed for this source — flush updates and stop.
209
209
+
// Use the last record's rkey as cursor so the tail resumes past this point.
210
210
+
const lastRecord = data.records[j];
211
211
+
const stopCursor = lastRecord?.uri?.split('/').pop() ?? data.cursor;
209
212
if (toUpdate.length > 0) await db.posts.bulkPut(toUpdate);
210
210
-
return { cursor: data.cursor, done: true };
213
213
+
return { cursor: stopCursor, done: true };
211
214
}
212
215
// Post exists from another source — queue source tag update
213
216
toUpdate.push({ ...existing, sources: [...existing.sources, source], fetchedAt: now });
···
222
225
if (toUpdate.length > 0) await db.posts.bulkPut(toUpdate);
223
226
224
227
const nextCursor = data.records.length > 0 ? data.cursor : undefined;
228
228
+
// Detect stalled cursor — if the API returns the same cursor we sent, stop.
229
229
+
if (nextCursor && nextCursor === cursor) {
230
230
+
return { cursor: nextCursor, done: true };
231
231
+
}
225
232
return { cursor: nextCursor, done: !nextCursor };
226
233
}
227
234
···
382
389
if (existing.sources.includes(source)) {
383
390
// Already indexed for this source — flush and stop
384
391
if (toPut.length > 0) await db.posts.bulkPut(toPut);
385
385
-
return { cursor: data.cursor, done: true };
392
392
+
return { cursor: data.cursor ?? cursor, done: true };
386
393
}
387
394
// Exists from another source — queue tag update
388
395
toPut.push({ ...existing, sources: [...existing.sources, source], fetchedAt: now });
···
401
408
if (toPut.length > 0) await db.posts.bulkPut(toPut);
402
409
403
410
const nextCursor = data.bookmarks.length > 0 ? data.cursor : undefined;
411
411
+
// Detect stalled cursor — if the API returns the same cursor we sent, stop.
412
412
+
if (nextCursor && nextCursor === cursor) {
413
413
+
return { cursor: nextCursor, done: true };
414
414
+
}
404
415
return { cursor: nextCursor, done: !nextCursor };
405
416
}
406
417