Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix(batch): renable doBatchRead when sortKey and blockHeight are not …
Browse files Browse the repository at this point in the history
…provided

This will at least improve the latency of full state evaluations when sortKey and blockHeight are not provided.
  • Loading branch information
dtfiedler committed Feb 29, 2024
1 parent e33d8f9 commit 00c56a4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/api/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from 'warp-contracts';
import {
DEFAULT_EVALUATION_OPTIONS,
// DEFAULT_PAGES_PER_BATCH,
DEFAULT_PAGES_PER_BATCH,
allowedContractTypes,
} from '../constants';
import { ContractType, EvaluatedContractState } from '../types';
Expand Down Expand Up @@ -218,21 +218,22 @@ async function readThroughToContractState(
),
});

// only use batch read if no block height provided (it does not currently support block heights)
const doBatchRead = !!providedSortKey || providedBlockHeight === undefined;
// only use batch read if no block height or sort key provided
const doBatchRead = !providedSortKey && !providedBlockHeight;
logger?.debug('Evaluating contract state...', {
contractTxId,
cacheKey: cacheKey.toString(),
doBatchRead, // there is a bug in warp where readStateBatch is not properly using sortKeys
evaluationOptions,
});

// TODO: re-enable readStateBatch after sortKey is fixed
const readStatePromise = contract.readState(
providedSortKey || providedBlockHeight,
undefined,
signal,
);
const readStatePromise = doBatchRead
? contract.readStateBatch(DEFAULT_PAGES_PER_BATCH, undefined, signal)
: contract.readState(
providedSortKey || providedBlockHeight,
undefined,
signal,
);

// set cached value for multiple requests during initial promise
stateRequestMap.set(cacheId, readStatePromise);
Expand Down

0 comments on commit 00c56a4

Please sign in to comment.