Skip to content

Commit

Permalink
Add index creation to block_follower
Browse files Browse the repository at this point in the history
  • Loading branch information
hsoerensen committed Jul 15, 2024
1 parent a044289 commit 20fd8b3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/block_follower.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ function createBlocksTableIfNotExists() {
});
}

function createIndexes() {
return new Promise((resolve, reject) => {
db.serialize(() => {
db.run(`CREATE INDEX IF NOT EXISTS proposer_idx ON blocks (proposer);`, err => {
if (err) return reject(err);
db.run(`CREATE INDEX IF NOT EXISTS timestamps_idx ON blocks (timestamp);`, err => {
if (err) return reject(err);
resolve();
});
});
});
});
}

function storeBlockInDb(block, proposer, timestamp) {
return new Promise((resolve, reject) => {
db.serialize(() => {
Expand Down Expand Up @@ -54,6 +68,7 @@ async function getHighestStoredBlock() {
(async () => {
// Ensure the blocks table exists
await createBlocksTableIfNotExists();
await createIndexes()

const highestStoredBlock = await getHighestStoredBlock();
console.log(`Highest stored block in the database: ${highestStoredBlock}`);
Expand Down

0 comments on commit 20fd8b3

Please # to comment.