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

Commit

Permalink
Merge pull request #104 from ar-io/sort-key-fix
Browse files Browse the repository at this point in the history
fix(batch): renable doBatchRead when sortKey and blockHeight are not …
  • Loading branch information
dtfiedler authored Feb 29, 2024
2 parents e33d8f9 + 00c56a4 commit bb76069
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 bb76069

Please sign in to comment.