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 diff --git a/packages/js-sdk/src/ApiClient.ts b/packages/js-sdk/src/ApiClient.ts index fe9d23006..b64eb4c36 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,19 @@ 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) 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[] = [] 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,