Skip to content

Commit 79dfb35

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

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/sdk/src/query_on_connect/query_on_connect.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export interface QueryOnConnectOptions {
2626
* @default [[DEFAULT_FORCE_QUERY_THRESHOLD_MS]]
2727
*/
2828
forceQueryThresholdMs?: number;
29+
/**
30+
* Maximum time range to look back when performing a store query on connect.
31+
* This value is capped server-side to 24h per single request; larger ranges
32+
* will be chunked by the SDK Store layer.
33+
* @default [[MAX_TIME_RANGE_QUERY_MS]] (24 hours)
34+
*/
35+
maxTimeRangeQueryMs?: number;
2936
}
3037

3138
export enum QueryOnConnectEvent {
@@ -51,6 +58,7 @@ export class QueryOnConnect<
5158
private lastSuccessfulQuery: number;
5259
private lastTimeOffline: number;
5360
private readonly forceQueryThresholdMs: number;
61+
private readonly maxTimeRangeQueryMs: number;
5462

5563
public constructor(
5664
public decoders: IDecoder<T>[],
@@ -67,6 +75,8 @@ export class QueryOnConnect<
6775
this.lastTimeOffline = 0;
6876
this.forceQueryThresholdMs =
6977
options?.forceQueryThresholdMs ?? DEFAULT_FORCE_QUERY_THRESHOLD_MS;
78+
this.maxTimeRangeQueryMs =
79+
options?.maxTimeRangeQueryMs ?? MAX_TIME_RANGE_QUERY_MS;
7080
}
7181

7282
public start(): void {
@@ -140,7 +150,7 @@ export class QueryOnConnect<
140150
return calculateTimeRange(
141151
Date.now(),
142152
this.lastSuccessfulQuery,
143-
MAX_TIME_RANGE_QUERY_MS
153+
this.maxTimeRangeQueryMs
144154
);
145155
}
146156

packages/sdk/src/reliable_channel/reliable_channel.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ 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+
* This is capped to 24h per request server-side; longer windows will be
118+
* chunked by the Store SDK.
119+
* @default 24h
120+
*/
121+
initialQueryLookbackMs?: number;
114122
};
115123

116124
/**
@@ -190,7 +198,12 @@ export class ReliableChannel<
190198
[this.decoder],
191199
peerManagerEvents,
192200
node.events,
193-
this._retrieve.bind(this)
201+
this._retrieve.bind(this),
202+
{
203+
maxTimeRangeQueryMs: options?.initialQueryLookbackMs,
204+
// Keep existing default unless user overrides
205+
forceQueryThresholdMs: undefined
206+
}
194207
);
195208
}
196209
}

0 commit comments

Comments
 (0)