Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Contacts.ConsentList.load() #671

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/js-sdk/src/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
export type QueryAllOptions = {
direction?: messageApi.SortDirection
limit?: number
pageSize?: number
}

export type QueryStreamOptions = Flatten<
Expand Down Expand Up @@ -317,14 +318,17 @@
{
direction = SortDirection.SORT_DIRECTION_ASCENDING,
limit,
pageSize,
}: QueryAllOptions
): Promise<messageApi.Envelope[]> {
const out: messageApi.Envelope[] = []
const maxPageSize = params.contentTopic.startsWith('userpreferences-') ? 500 : 100;

Check failure on line 325 in packages/js-sdk/src/ApiClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·?·500·:·100;` with `⏎······?·500⏎······:·100`

Check failure on line 326 in packages/js-sdk/src/ApiClient.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `····`
// 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)
Expand Down
2 changes: 1 addition & 1 deletion packages/js-sdk/src/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading