Fix cursor-based pagination with lexicographic ordering for composite fields (#12467)
# Fix cursor-based pagination with lexicographic ordering for composite
fields
## Bug
The existing cursor-based pagination implementation had a bug when
handling composite fields.
When paginating through results sorted by composite fields (like
`fullName` with sub-properties `firstName` and`lastName`), the WHERE
conditions generated for cursor positioning were incorrect, leading to
records being skipped.
The previous implementation was generating wrong WHERE conditions:
For example, when paginating with a cursor like `{ firstName: 'John',
lastName: 'Doe' }`, it would generate:
```sql
WHERE firstName > 'John' AND lastName > 'Doe'
```
This is incorrect because it would miss records like `{ firstName:
'John', lastName: 'Smith' }` which should be included in forward
pagination.
## Fix
Create a new util to use proper lexicographic order when sorting a
composite field.
---------
Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
co-authored by
Charles Bochet
Charles Bochet
parent
4cea354838
commit
d4995ab54e
@@ -0,0 +1,12 @@
|
||||
export const computeOperator = (
|
||||
isAscending: boolean,
|
||||
isForwardPagination: boolean,
|
||||
): string => {
|
||||
return isAscending
|
||||
? isForwardPagination
|
||||
? 'gt'
|
||||
: 'lt'
|
||||
: isForwardPagination
|
||||
? 'lt'
|
||||
: 'gt';
|
||||
};
|
||||
Reference in New Issue
Block a user