From 01f8ff4b7c6f36f6869297ae1df678fc1c3e15b9 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 14 Nov 2022 15:52:36 -0800 Subject: [PATCH 1/2] fix(searchcontroller): pre-fetch meta if backfill is set and we dont have the defaultpagesize --- packages/snap-controller/src/Search/SearchController.ts | 9 ++++++++- .../src/Search/Stores/SearchPaginationStore.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/snap-controller/src/Search/SearchController.ts b/packages/snap-controller/src/Search/SearchController.ts index 6e68d32ed..5a843661a 100644 --- a/packages/snap-controller/src/Search/SearchController.ts +++ b/packages/snap-controller/src/Search/SearchController.ts @@ -274,7 +274,14 @@ export class SearchController extends AbstractController { if (this.config.settings?.infinite.backfill && !previousResults.length) { // figure out how many pages of results to backfill and wait on all responses - const pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize; + let pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize; + + if (!pageSize) { + //unfortunatly we need to fetch meta to know the default pagesize before we can continue. + const meta = await this.client.meta(); + pageSize = meta.pagination.defaultPageSize; + } + let pagesNeeded1 = params.pagination?.page && params.pagination?.page > this.config.settings?.infinite.backfill ? this.config.settings?.infinite.backfill diff --git a/packages/snap-store-mobx/src/Search/Stores/SearchPaginationStore.ts b/packages/snap-store-mobx/src/Search/Stores/SearchPaginationStore.ts index f8b87343e..980fb9f17 100644 --- a/packages/snap-store-mobx/src/Search/Stores/SearchPaginationStore.ts +++ b/packages/snap-store-mobx/src/Search/Stores/SearchPaginationStore.ts @@ -34,7 +34,7 @@ export class SearchPaginationStore { this.page = paginationData.page!; this.pageSize = paginationData.pageSize!; this.totalResults = paginationData.totalResults!; - this.defaultPageSize = meta?.pagination?.defaultPageSize! || 24; + this.defaultPageSize = meta?.pagination?.defaultPageSize!; this.totalPages = paginationData.totalPages!; this.pageSizeOptions = [ From 17fa02a7f43b0d83b8dabf403248688088e2be05 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 16 Nov 2022 10:49:58 -0800 Subject: [PATCH 2/2] fix(searchcontroller): backfill page size bugfix --- packages/snap-controller/src/Search/SearchController.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/snap-controller/src/Search/SearchController.ts b/packages/snap-controller/src/Search/SearchController.ts index 5a843661a..9280b89d1 100644 --- a/packages/snap-controller/src/Search/SearchController.ts +++ b/packages/snap-controller/src/Search/SearchController.ts @@ -272,14 +272,13 @@ export class SearchController extends AbstractController { let previousResults = this.previousResults; const backfills = []; + let pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize; if (this.config.settings?.infinite.backfill && !previousResults.length) { // figure out how many pages of results to backfill and wait on all responses - let pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize; - if (!pageSize) { //unfortunatly we need to fetch meta to know the default pagesize before we can continue. const meta = await this.client.meta(); - pageSize = meta.pagination.defaultPageSize; + pageSize = meta.pagination?.defaultPageSize!; } let pagesNeeded1 = @@ -334,7 +333,8 @@ export class SearchController extends AbstractController { } //we need to overwrite the pagination params so the ui doesnt get confused. - response.pagination.pageSize = params.pagination?.pageSize || this.store.pagination.pageSize || this.store.pagination.defaultPageSize; + response.pagination.pageSize = pageSize; + response.pagination.totalPages = Math.ceil(response.pagination.totalResults / response.pagination.pageSize); response.pagination.page = params.pagination?.page; //set the response results after all backfill promises are resolved. @@ -393,6 +393,7 @@ export class SearchController extends AbstractController { afterSearchProfile.stop(); this.log.profile(afterSearchProfile); + // store previous results for infinite usage if (this.config.settings?.infinite) { this.previousResults = JSON.parse(JSON.stringify(response.results)); }