Skip to content

Commit d136595

Browse files
chore(sds): allow specifying lookback time range for store query
1 parent 79dd001 commit d136595

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/sdk/src/query_on_connect/query_on_connect.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export interface QueryOnConnectOptions {
2626
* @default [[DEFAULT_FORCE_QUERY_THRESHOLD_MS]]
2727
*/
2828
forceQueryThresholdMs?: number;
29+
/**
30+
* Maximum lookback window for the initial store query performed by
31+
* QueryOnConnect when a store peer connects.
32+
* @default [[MAX_TIME_RANGE_QUERY_MS]] (24 hours)
33+
*/
34+
maxTimeRangeQueryMs?: number;
2935
}
3036

3137
export enum QueryOnConnectEvent {
@@ -51,6 +57,7 @@ export class QueryOnConnect<
5157
private lastSuccessfulQuery: number;
5258
private lastTimeOffline: number;
5359
private readonly forceQueryThresholdMs: number;
60+
private readonly maxTimeRangeQueryMs: number;
5461

5562
public constructor(
5663
public decoders: IDecoder<T>[],
@@ -67,6 +74,8 @@ export class QueryOnConnect<
6774
this.lastTimeOffline = 0;
6875
this.forceQueryThresholdMs =
6976
options?.forceQueryThresholdMs ?? DEFAULT_FORCE_QUERY_THRESHOLD_MS;
77+
this.maxTimeRangeQueryMs =
78+
options?.maxTimeRangeQueryMs ?? MAX_TIME_RANGE_QUERY_MS;
7079
}
7180

7281
public start(): void {
@@ -140,7 +149,7 @@ export class QueryOnConnect<
140149
return calculateTimeRange(
141150
Date.now(),
142151
this.lastSuccessfulQuery,
143-
MAX_TIME_RANGE_QUERY_MS
152+
this.maxTimeRangeQueryMs
144153
);
145154
}
146155

packages/sdk/src/reliable_channel/reliable_channel.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ export type ReliableChannelOptions = MessageChannelOptions & {
111111
* @default 1000 (1 second)
112112
*/
113113
processTaskMinElapseMs?: number;
114+
/**
115+
* Maximum lookback window for the initial store query performed by
116+
* QueryOnConnect when a store peer connects.
117+
* @default 24h
118+
*/
119+
initialQueryLookbackMs?: number;
114120
};
115121

116122
/**
@@ -190,7 +196,12 @@ export class ReliableChannel<
190196
[this.decoder],
191197
peerManagerEvents,
192198
node.events,
193-
this._retrieve.bind(this)
199+
this._retrieve.bind(this),
200+
{
201+
maxTimeRangeQueryMs: options?.initialQueryLookbackMs,
202+
// Keep existing default unless user overrides
203+
forceQueryThresholdMs: undefined
204+
}
194205
);
195206
}
196207
}

0 commit comments

Comments
 (0)