(sortState: SortState)
| 71 | } |
| 72 | |
| 73 | async function getAllNotes(sortState: SortState) { |
| 74 | const paginatedNotes = [] as Note[] |
| 75 | let count = 0 |
| 76 | do { |
| 77 | count++ |
| 78 | if (count > 1000) throwExp(`loop count is ${count}, did you screw up?`) |
| 79 | const last = paginatedNotes.at(-1) |
| 80 | const cursor = |
| 81 | last == null |
| 82 | ? undefined |
| 83 | : ({ |
| 84 | noteEdited: dateToEpoch(last.noteEdited), |
| 85 | subscribers: last.subscribers, |
| 86 | comments: last.comments, |
| 87 | til: maybeDateToEpoch(last.til) ?? undefined, |
| 88 | 'note.id': last.id, |
| 89 | } satisfies NoteCursor) |
| 90 | const page = await getNotes( |
| 91 | { |
| 92 | nook, |
| 93 | sortState: cloneDeep(sortState), // getNotes mutates this, which is fine in prod but not for testing |
| 94 | cursor, |
| 95 | }, |
| 96 | userId, |
| 97 | ) |
| 98 | if (page.length === 0) { |
| 99 | break |
| 100 | } else { |
| 101 | paginatedNotes.push(...page) |
| 102 | } |
| 103 | } while (true as boolean) |
| 104 | return paginatedNotes |
| 105 | } |
| 106 | |
| 107 | test('cursor/keyset pagination works for getNotes', async () => { |
| 108 | const sortState = fc |
no test coverage detected