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

Commit

Permalink
🎨 Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
priojeetpriyom committed Nov 9, 2023
1 parent 1736d0f commit e1d53e9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions services/blockchain-indexer/shared/indexer/blockchainIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,15 @@ const indexBlock = async job => {
};

// Returns a list of all indexed blocks since the minimum block height from job
const getBlocksToDelete = async (blocksFromJob) => {
const getBlocksToDelete = async blocksFromJob => {
if (!blocksFromJob.length) {
return blocksFromJob;
}
const blocksTable = await getBlocksTable();
const minBlockHeight = blocksFromJob.reduce((minHeight, block) => Math.min(minHeight, block.height), blocksFromJob[0].height);
const minBlockHeight = blocksFromJob.reduce(
(minHeight, block) => Math.min(minHeight, block.height),
blocksFromJob[0].height,
);

const blocksToRemove = await blocksTable.find(
{
Expand Down Expand Up @@ -568,7 +571,10 @@ const deleteIndexedBlocks = async job => {
{ concurrency: 1 },
);

await blocksTable.delete(blockIDs.map(blockID => ({ id: blockID })), dbTrx);
await blocksTable.delete(
blockIDs.map(blockID => ({ id: blockID })),
dbTrx,
);
await commitDBTransaction(dbTrx);

// Add safety check to ensure that the DB transaction is actually committed
Expand Down Expand Up @@ -654,13 +660,17 @@ const getPendingDeleteJobCount = async () => {
const scheduleBlockDeletion = async block => {
block = Array.isArray(block) ? block : [block];
deleteIndexedBlocksQueue.add({ blocks: [...block] });
}
};

const indexNewBlock = async block => {
const blocksTable = await getBlocksTable();
logger.info(`Scheduling indexing of new block: ${block.id} at height ${block.height}.`);

const [blockFromDB] = await blocksTable.find({ height: block.height, limit: 1 }, ['id', 'height', 'generatorAddress']);
const [blockFromDB] = await blocksTable.find({ height: block.height, limit: 1 }, [
'id',
'height',
'generatorAddress',
]);

// Schedule block deletion incase unprocessed fork found
if (blockFromDB && blockFromDB.id !== block.id) {
Expand Down

0 comments on commit e1d53e9

Please sign in to comment.