From bd2dd9e4c27660adc53bafd0c7054b01f8526403 Mon Sep 17 00:00:00 2001 From: Marco Mele Date: Mon, 7 Oct 2024 16:26:39 -0500 Subject: [PATCH 1/4] Update ApiClient.ts --- packages/js-sdk/src/ApiClient.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/js-sdk/src/ApiClient.ts b/packages/js-sdk/src/ApiClient.ts index fe9d23006..2c6f36bbf 100644 --- a/packages/js-sdk/src/ApiClient.ts +++ b/packages/js-sdk/src/ApiClient.ts @@ -66,6 +66,7 @@ export type QueryParams = { export type QueryAllOptions = { direction?: messageApi.SortDirection limit?: number + pageSize?: number } export type QueryStreamOptions = Flatten< @@ -317,14 +318,17 @@ export default class HttpApiClient implements ApiClient { { direction = SortDirection.SORT_DIRECTION_ASCENDING, limit, + pageSize, }: QueryAllOptions ): Promise { const out: messageApi.Envelope[] = [] + const maxPageSize = params.contentTopic.startsWith('userpreferences-') ? 500 : 100; + // Use queryIteratePages for better performance. 1/100th the number of Promises to resolve compared to queryStream for await (const page of this.queryIteratePages(params, { direction, // If there is a limit of < 100, use that as the page size. Otherwise use 100 and stop if/when limit reached. - pageSize: limit && limit < 100 ? limit : 100, + pageSize: pageSize ? Math.min(pageSize, maxPageSize) : maxPageSize, })) { for (const envelope of page) { out.push(envelope) From 564e64c7734734d3d47fbe98ec809667db855efa Mon Sep 17 00:00:00 2001 From: Marco Mele Date: Mon, 7 Oct 2024 16:29:16 -0500 Subject: [PATCH 2/4] Update Contacts.ts --- packages/js-sdk/src/Contacts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js-sdk/src/Contacts.ts b/packages/js-sdk/src/Contacts.ts index 1bbe68c6a..749db20d0 100644 --- a/packages/js-sdk/src/Contacts.ts +++ b/packages/js-sdk/src/Contacts.ts @@ -238,7 +238,7 @@ export class ConsentList { [timestampNs, message] as [string | undefined, Uint8Array], { // special exception for private preferences topic - limit: 500, + pageSize: 500, // ensure messages are in ascending order direction: messageApi.SortDirection.SORT_DIRECTION_ASCENDING, startTime, From 8de95991f3b95a681430e3ea6c2f3f2d6c55648e Mon Sep 17 00:00:00 2001 From: Marco Mele Date: Mon, 7 Oct 2024 20:17:34 -0500 Subject: [PATCH 3/4] ListMessageOptions --- packages/js-sdk/src/ApiClient.ts | 6 ++++-- packages/js-sdk/src/Client.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/js-sdk/src/ApiClient.ts b/packages/js-sdk/src/ApiClient.ts index 2c6f36bbf..b64eb4c36 100644 --- a/packages/js-sdk/src/ApiClient.ts +++ b/packages/js-sdk/src/ApiClient.ts @@ -322,8 +322,10 @@ export default class HttpApiClient implements ApiClient { }: QueryAllOptions ): Promise { const out: messageApi.Envelope[] = [] - const maxPageSize = params.contentTopic.startsWith('userpreferences-') ? 500 : 100; - + const maxPageSize = params.contentTopic.startsWith('userpreferences-') + ? 500 + : 100 + // Use queryIteratePages for better performance. 1/100th the number of Promises to resolve compared to queryStream for await (const page of this.queryIteratePages(params, { direction, diff --git a/packages/js-sdk/src/Client.ts b/packages/js-sdk/src/Client.ts index 907e09b9d..ed5cac34e 100644 --- a/packages/js-sdk/src/Client.ts +++ b/packages/js-sdk/src/Client.ts @@ -65,6 +65,7 @@ export type ListMessagesOptions = { endTime?: Date limit?: number direction?: messageApi.SortDirection + pageSize?: number } export type ListMessagesPaginatedOptions = { @@ -723,7 +724,7 @@ export default class Client { if (!opts) { opts = {} } - const { startTime, endTime, limit } = opts + const { startTime, endTime, limit, pageSize } = opts const envelopes = await this.apiClient.query( { contentTopic: topic, startTime, endTime }, @@ -731,6 +732,7 @@ export default class Client { direction: opts.direction || messageApi.SortDirection.SORT_DIRECTION_ASCENDING, limit, + pageSize, } ) const results: Out[] = [] From 760da4a08a682a5597f065955285fe57b4888b6e Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 7 Oct 2024 18:38:40 -0700 Subject: [PATCH 4/4] Create shy-news-hang.md --- .changeset/shy-news-hang.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/shy-news-hang.md diff --git a/.changeset/shy-news-hang.md b/.changeset/shy-news-hang.md new file mode 100644 index 000000000..a80595e66 --- /dev/null +++ b/.changeset/shy-news-hang.md @@ -0,0 +1,5 @@ +--- +"@xmtp/xmtp-js": patch +--- + +Allow larger page size and limit in the API client when querying for consent