chore(sds): allow specifying lookback time range for store query

This commit is contained in:
Danish Arora 2025-09-22 22:51:22 +05:30
parent 79dd001b1f
commit d136595d18
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
2 changed files with 22 additions and 2 deletions

View File

@ -26,6 +26,12 @@ export interface QueryOnConnectOptions {
* @default [[DEFAULT_FORCE_QUERY_THRESHOLD_MS]] * @default [[DEFAULT_FORCE_QUERY_THRESHOLD_MS]]
*/ */
forceQueryThresholdMs?: number; 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)
*/
maxTimeRangeQueryMs?: number;
} }
export enum QueryOnConnectEvent { export enum QueryOnConnectEvent {
@ -51,6 +57,7 @@ export class QueryOnConnect<
private lastSuccessfulQuery: number; private lastSuccessfulQuery: number;
private lastTimeOffline: number; private lastTimeOffline: number;
private readonly forceQueryThresholdMs: number; private readonly forceQueryThresholdMs: number;
private readonly maxTimeRangeQueryMs: number;
public constructor( public constructor(
public decoders: IDecoder<T>[], public decoders: IDecoder<T>[],
@ -67,6 +74,8 @@ export class QueryOnConnect<
this.lastTimeOffline = 0; this.lastTimeOffline = 0;
this.forceQueryThresholdMs = this.forceQueryThresholdMs =
options?.forceQueryThresholdMs ?? DEFAULT_FORCE_QUERY_THRESHOLD_MS; options?.forceQueryThresholdMs ?? DEFAULT_FORCE_QUERY_THRESHOLD_MS;
this.maxTimeRangeQueryMs =
options?.maxTimeRangeQueryMs ?? MAX_TIME_RANGE_QUERY_MS;
} }
public start(): void { public start(): void {
@ -140,7 +149,7 @@ export class QueryOnConnect<
return calculateTimeRange( return calculateTimeRange(
Date.now(), Date.now(),
this.lastSuccessfulQuery, this.lastSuccessfulQuery,
MAX_TIME_RANGE_QUERY_MS this.maxTimeRangeQueryMs
); );
} }

View File

@ -111,6 +111,12 @@ export type ReliableChannelOptions = MessageChannelOptions & {
* @default 1000 (1 second) * @default 1000 (1 second)
*/ */
processTaskMinElapseMs?: number; processTaskMinElapseMs?: number;
/**
* Maximum lookback window for the initial store query performed by
* QueryOnConnect when a store peer connects.
* @default 24h
*/
initialQueryLookbackMs?: number;
}; };
/** /**
@ -190,7 +196,12 @@ export class ReliableChannel<
[this.decoder], [this.decoder],
peerManagerEvents, peerManagerEvents,
node.events, node.events,
this._retrieve.bind(this) this._retrieve.bind(this),
{
maxTimeRangeQueryMs: options?.initialQueryLookbackMs,
// Keep existing default unless user overrides
forceQueryThresholdMs: undefined
}
); );
} }
} }