From 00c56a40f0f65ccccb103bb388a0f19714d3aa46 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Thu, 29 Feb 2024 12:42:35 -0700 Subject: [PATCH] fix(batch): renable doBatchRead when sortKey and blockHeight are not provided This will at least improve the latency of full state evaluations when sortKey and blockHeight are not provided. --- src/api/warp.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/api/warp.ts b/src/api/warp.ts index d01e088..9f4bef4 100644 --- a/src/api/warp.ts +++ b/src/api/warp.ts @@ -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'; @@ -218,8 +218,8 @@ 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(), @@ -227,12 +227,13 @@ async function readThroughToContractState( 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);