Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion packages/sdk/src/query_on_connect/query_on_connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export interface QueryOnConnectOptions {
* @default [[DEFAULT_FORCE_QUERY_THRESHOLD_MS]]
*/
forceQueryThresholdMs?: number;
/**
* Maximum lookback window for the initial store query performed by
* QueryOnConnect when a store peer connects.
* @default [[MAX_TIME_RANGE_QUERY_MS]] (24 hours)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if you use a value over 24hrs, the underlying store protocol will split it in 24 hrs queries.

*/
maxTimeRangeQueryMs?: number;
}

export enum QueryOnConnectEvent {
Expand All @@ -51,6 +57,7 @@ export class QueryOnConnect<
private lastSuccessfulQuery: number;
private lastTimeOffline: number;
private readonly forceQueryThresholdMs: number;
private readonly maxTimeRangeQueryMs: number;

public constructor(
public decoders: IDecoder<T>[],
Expand All @@ -67,6 +74,8 @@ export class QueryOnConnect<
this.lastTimeOffline = 0;
this.forceQueryThresholdMs =
options?.forceQueryThresholdMs ?? DEFAULT_FORCE_QUERY_THRESHOLD_MS;
this.maxTimeRangeQueryMs =
options?.maxTimeRangeQueryMs ?? MAX_TIME_RANGE_QUERY_MS;
}

public start(): void {
Expand Down Expand Up @@ -140,7 +149,7 @@ export class QueryOnConnect<
return calculateTimeRange(
Date.now(),
this.lastSuccessfulQuery,
MAX_TIME_RANGE_QUERY_MS
this.maxTimeRangeQueryMs
);
}

Expand Down
13 changes: 12 additions & 1 deletion packages/sdk/src/reliable_channel/reliable_channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export type ReliableChannelOptions = MessageChannelOptions & {
* @default 1000 (1 second)
*/
processTaskMinElapseMs?: number;
/**
* Maximum lookback window for the initial store query performed by
* QueryOnConnect when a store peer connects.
* @default 24h
*/
initialQueryLookbackMs?: number;
};

/**
Expand Down Expand Up @@ -190,7 +196,12 @@ export class ReliableChannel<
[this.decoder],
peerManagerEvents,
node.events,
this._retrieve.bind(this)
this._retrieve.bind(this),
{
maxTimeRangeQueryMs: options?.initialQueryLookbackMs,
// Keep existing default unless user overrides
forceQueryThresholdMs: undefined
}
);
}
}
Expand Down
Loading