refactor: Helpers.generateCollection so that total count and a bound function can be passed in, #13153

This commit is contained in:
Julian Lam
2025-05-06 12:09:07 -04:00
parent 450ce3b85c
commit 7f59238d3a

View File

@@ -448,11 +448,11 @@ Helpers.makeSet = (object, properties) => new Set(properties.reduce((memo, prope
[object[property]] :
[]), []));
Helpers.generateCollection = async ({ set, method, page, perPage, url }) => {
Helpers.generateCollection = async ({ set, method, count, page, perPage, url }) => {
if (!method) {
method = db.getSortedSetRange;
method = db.getSortedSetRange.bind(null, set);
}
const count = await db.sortedSetCard(set);
count = count || await db.sortedSetCard(set);
const pageCount = Math.max(1, Math.ceil(count / perPage));
let items = [];
let paginate = true;
@@ -470,7 +470,7 @@ Helpers.generateCollection = async ({ set, method, page, perPage, url }) => {
const start = Math.max(0, ((page - 1) * perPage) - 1);
const stop = Math.max(0, start + perPage - 1);
items = await method(set, start, stop);
items = await method.call(null, start, stop);
}
const object = {