Skip to content

Commit 4dafe00

Browse files
Merge #526
526: Add an orderby when fetching from the database r=bidoubiwa a=bidoubiwa When using PostgreSQL on a large database, if you paginate using offset, it may happen that psql do not follow the same rule to order the documents. Meaning that, if I make multiple requests with different offsets, I might receive back documents that I already fetched before. Exemple: Running `Select * FROM x OFFSET 100` two times might return different documents. To tackle that issue, we need to add an `order by` during the request. This ensures the database follows the same order for the documents. Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 7f18389 + bbd114d commit 4dafe00

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

server/__tests__/content-types.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('Tests content types', () => {
114114
start: 0,
115115
limit: 500,
116116
filters: {},
117-
sort: {},
117+
sort: 'id',
118118
populate: '*',
119119
publicationState: 'live',
120120
}

server/services/content-types/content-types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ module.exports = ({ strapi }) => ({
157157
* @param {number} [options.start] - Pagination start.
158158
* @param {number} [options.limit] - Number of entries to return.
159159
* @param {object} [options.filters] - Filters to use.
160-
* @param {object} [options.sort] - Order definition.
160+
* @param {object|string} [options.sort] - Order definition.
161161
* @param {object} [options.populate] - Relations, components and dynamic zones to populate.
162162
* @param {object} [options.publicationState] - Publication state: live or preview.
163163
* @param {string} [options.contentType] - Content type.
@@ -170,7 +170,7 @@ module.exports = ({ strapi }) => ({
170170
start = 0,
171171
limit = 500,
172172
filters = {},
173-
sort = {},
173+
sort = 'id',
174174
populate = '*',
175175
publicationState = 'live',
176176
}) {

0 commit comments

Comments
 (0)