feat: sortKey param for readStateBatch
This commit is contained in:
@@ -122,7 +122,11 @@ export interface Contract<State = unknown> {
|
|||||||
*
|
*
|
||||||
* Consider this as an experimental feature
|
* Consider this as an experimental feature
|
||||||
*/
|
*/
|
||||||
readStateBatch(pagesPerBatch: number, signal: AbortSignal): Promise<SortKeyCacheResult<EvalStateResult<State>>>;
|
readStateBatch(
|
||||||
|
pagesPerBatch: number,
|
||||||
|
sortKey?: string,
|
||||||
|
signal?: AbortSignal
|
||||||
|
): Promise<SortKeyCacheResult<EvalStateResult<State>>>;
|
||||||
|
|
||||||
readStateFor(
|
readStateFor(
|
||||||
sortKey: string,
|
sortKey: string,
|
||||||
|
|||||||
@@ -226,14 +226,18 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
return this.readState(sortKey, interactions, signal);
|
return this.readState(sortKey, interactions, signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
async readStateBatch(pagesPerBatch = 1, signal: AbortSignal): Promise<SortKeyCacheResult<EvalStateResult<State>>> {
|
async readStateBatch(
|
||||||
|
pagesPerBatch = 1,
|
||||||
|
sortKey?: string,
|
||||||
|
signal?: AbortSignal
|
||||||
|
): Promise<SortKeyCacheResult<EvalStateResult<State>>> {
|
||||||
if (!this.isRoot()) {
|
if (!this.isRoot()) {
|
||||||
throw new Error('readStateBatch is only allowed for root contract calls');
|
throw new Error('readStateBatch is only allowed for root contract calls');
|
||||||
}
|
}
|
||||||
if (pagesPerBatch < 1) {
|
if (pagesPerBatch < 1) {
|
||||||
throw new Error('At least one page per batch is required');
|
throw new Error('At least one page per batch is required');
|
||||||
}
|
}
|
||||||
if (signal.aborted) {
|
if (signal?.aborted) {
|
||||||
throw new AbortError('readStateBatch aborted');
|
throw new AbortError('readStateBatch aborted');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,8 +255,8 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
do {
|
do {
|
||||||
const batchBenchmark = Benchmark.measure();
|
const batchBenchmark = Benchmark.measure();
|
||||||
this.logger.debug(`Loading ${++batchesLoaded}`, evaluationOptions);
|
this.logger.debug(`Loading ${++batchesLoaded}`, evaluationOptions);
|
||||||
interactions = await interactionsLoader.load(contractTxId, cachedState?.sortKey, undefined, evaluationOptions);
|
interactions = await interactionsLoader.load(contractTxId, cachedState?.sortKey, sortKey, evaluationOptions);
|
||||||
if (signal.aborted) {
|
if (signal?.aborted) {
|
||||||
throw new AbortError('readStateBatch aborted');
|
throw new AbortError('readStateBatch aborted');
|
||||||
}
|
}
|
||||||
if (interactions.length == 0) {
|
if (interactions.length == 0) {
|
||||||
@@ -260,7 +264,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
|||||||
}
|
}
|
||||||
this.logger.debug(`Evaluating ${interactions.length} in ${batchesLoaded}`);
|
this.logger.debug(`Evaluating ${interactions.length} in ${batchesLoaded}`);
|
||||||
cachedState = await this.readStateFor(cachedState?.sortKey || genesisSortKey, interactions, signal);
|
cachedState = await this.readStateFor(cachedState?.sortKey || genesisSortKey, interactions, signal);
|
||||||
if (signal.aborted) {
|
if (signal?.aborted) {
|
||||||
throw new AbortError('readStateBatch aborted');
|
throw new AbortError('readStateBatch aborted');
|
||||||
}
|
}
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
|
|||||||
Reference in New Issue
Block a user