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

fix(batch): renable doBatchRead when sortKey and blockHeight are not … #104

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
} 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 @@ -107,7 +107,7 @@
constructor(
public readonly contractTxId: string,
public readonly functionName: string,
public readonly input: any,

Check warning on line 110 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
public readonly warp: Warp,
public readonly evaluationOptions: Partial<EvaluationOptions>,
public readonly logger?: winston.Logger,
Expand Down Expand Up @@ -218,21 +218,22 @@
),
});

// 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 Expand Up @@ -308,8 +309,8 @@
return new NotFoundError(error.message);
} else if (
(error instanceof Error &&
(error as any).type &&

Check warning on line 312 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
['TX_NOT_FOUND', 'TX_INVALID'].includes((error as any).type)) ||

Check warning on line 313 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
(typeof error === 'string' && (error as string).includes('TX_INVALID'))
) {
return new NotFoundError(`Contract not found. ${error}`);
Expand Down Expand Up @@ -481,7 +482,7 @@
functionName: string;
input: ParsedUrlQuery;
}): Promise<{
result: any;

Check warning on line 485 in src/api/warp.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
evaluationOptions: Partial<EvaluationOptions>;
}> {
try {
Expand Down
Loading