Skip to content

Commit 60dd8e8

Browse files
committed
fix: thoughts api
1 parent 5549158 commit 60dd8e8

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

server/api/thought/index.get.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ export default eventHandler(async (event) => {
4343
publishedAt: dbThought.publishedAt,
4444
updatedAt: dbThought.updatedAt,
4545
content: kvThought.content,
46-
...kvThought.parsed,
46+
body: kvThought.parsed.body,
4747
} as Thought
4848
}),
4949
)
5050

5151
const validThoughts = thoughts.filter((thought): thought is Thought => thought !== null)
5252

53-
// Calculate next cursor (timestamp of the last item)
54-
const nextCursor = hasMore && validThoughts.length > 0
55-
? Math.floor(validThoughts[validThoughts.length - 1].publishedAt.getTime() / 1000)
53+
// Calculate next cursor based on the last database item processed, not the last valid thought
54+
// This ensures pagination continues correctly even if some KV lookups fail
55+
const nextCursor = hasMore && dbThoughts.length > limit
56+
? Math.floor(dbThoughts[limit].publishedAt.getTime() / 1000)
5657
: null
5758

5859
return {

0 commit comments

Comments
 (0)