Skip to content

Commit 4c31744

Browse files
authored
Merge pull request #284 from performant-software/RB-getall-method
Changing `getAll` method to fetch in batches of 10
2 parents 7513964 + 29c2739 commit 4c31744

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/services/coreData/base.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const REQUEST_PARAMS = {
77
per_page: 0
88
};
99

10+
const REQUEST_PARAMS_GETALL = {
11+
per_page: 10
12+
};
13+
1014
/**
1115
* Base class for all Core Data services. This class is responsible for fetching data from either the Astro
1216
* content layer or directly from Core Data.
@@ -39,8 +43,19 @@ class Base {
3943
const entries = await getCollection(this.name);
4044
records = _.map(entries, (entry) => entry.data);
4145
} else {
42-
const response = await this.service.fetchAll(REQUEST_PARAMS);
43-
records = response[this.name];
46+
records = [];
47+
let pages = 1;
48+
for (let page = 1; page <= pages; page++ ) {
49+
try {
50+
const response = await this.service.fetchAll(_.extend(REQUEST_PARAMS_GETALL, { page }));
51+
if (response.list?.pages > pages) {
52+
pages = response.list?.pages;
53+
}
54+
records = [...records, ...response[this.name]];
55+
} catch (error) {
56+
console.log(error);
57+
}
58+
}
4459
}
4560

4661
return {

0 commit comments

Comments
 (0)