Skip to content

Commit 90f866e

Browse files
authored
Fix casting db type as nullable rather than optional (#474)
* Fix casting db type as nullable rather than optional * Add comment about Nullable.t use
1 parent a387548 commit 90f866e

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

codegenerator/cli/templates/static/codegen/src/db/DbFunctions.res

+7-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ module ChainMetadata = {
9898
@as("chain_id") chainId: int,
9999
@as("block_height") blockHeight: int,
100100
@as("start_block") startBlock: int,
101-
@as("end_block") endBlock: option<int>,
102-
@as("first_event_block_number") firstEventBlockNumber: option<int>,
103-
@as("latest_processed_block") latestProcessedBlock: option<int>,
104-
@as("num_events_processed") numEventsProcessed: option<int>,
101+
// The values below could use `Js.Null.t` instead of `Js.Nullable.t`
102+
// It just needs to be confiremed that the postgres lib never returns
103+
// undefined.
104+
@as("end_block") endBlock: Js.Nullable.t<int>,
105+
@as("first_event_block_number") firstEventBlockNumber: Js.Nullable.t<int>,
106+
@as("latest_processed_block") latestProcessedBlock: Js.Nullable.t<int>,
107+
@as("num_events_processed") numEventsProcessed: Js.Nullable.t<int>,
105108
@as("is_hyper_sync") poweredByHyperSync: bool,
106109
@as("num_batches_fetched") numBatchesFetched: int,
107110
@as("latest_fetched_block_number") latestFetchedBlockNumber: int,

codegenerator/cli/templates/static/codegen/src/eventFetching/ChainFetcher.res

+5-5
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ let makeFromDbState = async (
267267
}) => {
268268
// on restart, reset the events_processed gauge to the previous state
269269
switch numEventsProcessed {
270-
| Some(numEventsProcessed) =>
270+
| Value(numEventsProcessed) =>
271271
Prometheus.setEventsProcessedGuage(~number=numEventsProcessed, ~chainId)
272-
| None => () // do nothing if no events have been processed yet for this chain
272+
| Null | Undefined => () // do nothing if no events have been processed yet for this chain
273273
}
274274
(
275-
firstEventBlockNumber,
276-
latestProcessedBlock,
277-
numEventsProcessed,
275+
firstEventBlockNumber->Js.Nullable.toOption,
276+
latestProcessedBlock->Js.Nullable.toOption,
277+
numEventsProcessed->Js.Nullable.toOption,
278278
Env.updateSyncTimeOnRestart
279279
? None
280280
: timestampCaughtUpToHeadOrEndblock->Js.Nullable.toOption,

codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ let updateChainMetadataTable = async (cm: ChainManager.t, ~throttler: Throttler.
152152
startBlock: cf.chainConfig.startBlock,
153153
blockHeight: cf.currentBlockHeight,
154154
//optional fields
155-
endBlock: cf.chainConfig.endBlock, //this is already optional
156-
firstEventBlockNumber: cf->ChainFetcher.getFirstEventBlockNumber,
157-
latestProcessedBlock: cf.latestProcessedBlock, // this is already optional
158-
numEventsProcessed: Some(cf.numEventsProcessed),
155+
endBlock: cf.chainConfig.endBlock->Js.Nullable.fromOption, //this is already optional
156+
firstEventBlockNumber: cf->ChainFetcher.getFirstEventBlockNumber->Js.Nullable.fromOption,
157+
latestProcessedBlock: cf.latestProcessedBlock->Js.Nullable.fromOption, // this is already optional
158+
numEventsProcessed: Value(cf.numEventsProcessed),
159159
poweredByHyperSync: (cf.sourceManager->SourceManager.getActiveSource).poweredByHyperSync,
160160
numBatchesFetched: cf.numBatchesFetched,
161161
latestFetchedBlockNumber: latestFetchedBlock.blockNumber,

0 commit comments

Comments
 (0)