Skip to content

Commit

Permalink
fix: Drop the usage of useCursorV2 from the server
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Oct 5, 2024
1 parent c017328 commit 99c6232
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
10 changes: 5 additions & 5 deletions packages/shared/types/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ export const zGetBookmarksRequestSchema = z.object({
tagId: z.string().optional(),
listId: z.string().optional(),
limit: z.number().max(MAX_NUM_BOOKMARKS_PER_PAGE).optional(),
cursor: zCursorV2.or(z.date()).nullish(),
// TODO: Remove this field once all clients are updated to use the new cursor structure.
// This is done for backward comptability. If a client doesn't send this field, we'll assume it's an old client
// and repsond with the old cursor structure. Once all clients are updated, we can remove this field and drop the old cursor structure.
cursor: zCursorV2.nullish(),
// TODO: This was done for backward comptability. At this point, all clients should be settings this to true.
// The value is currently not being used, but keeping it so that client can still set it to true for older
// servers.
useCursorV2: z.boolean().optional(),
});
export type ZGetBookmarksRequest = z.infer<typeof zGetBookmarksRequestSchema>;

export const zGetBookmarksResponseSchema = z.object({
bookmarks: z.array(zBookmarkSchema),
nextCursor: zCursorV2.or(z.date()).nullable(),
nextCursor: zCursorV2.nullable(),
});
export type ZGetBookmarksResponse = z.infer<typeof zGetBookmarksResponseSchema>;

Expand Down
28 changes: 11 additions & 17 deletions packages/trpc/routers/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,13 @@ export const bookmarksAppRouter = router({
)
: undefined,
input.cursor
? input.cursor instanceof Date
? lte(bookmarks.createdAt, input.cursor)
: or(
lt(bookmarks.createdAt, input.cursor.createdAt),
and(
eq(bookmarks.createdAt, input.cursor.createdAt),
lte(bookmarks.id, input.cursor.id),
),
)
? or(
lt(bookmarks.createdAt, input.cursor.createdAt),
and(
eq(bookmarks.createdAt, input.cursor.createdAt),
lte(bookmarks.id, input.cursor.id),
),
)
: undefined,
),
)
Expand Down Expand Up @@ -677,14 +675,10 @@ export const bookmarksAppRouter = router({
let nextCursor = null;
if (bookmarksArr.length > input.limit) {
const nextItem = bookmarksArr.pop()!;
if (input.useCursorV2) {
nextCursor = {
id: nextItem.id,
createdAt: nextItem.createdAt,
};
} else {
nextCursor = nextItem.createdAt;
}
nextCursor = {
id: nextItem.id,
createdAt: nextItem.createdAt,
};
}

return { bookmarks: bookmarksArr, nextCursor };
Expand Down

0 comments on commit 99c6232

Please sign in to comment.