Database schema version 6 truncate the blocks table
This commit is contained in:
parent
1c575f1c93
commit
b1bd6f8fdb
@ -198,7 +198,7 @@ class Blocks {
|
|||||||
logger.info(`Indexing blocks from #${currentBlockHeight} to #${lastBlockToIndex}`);
|
logger.info(`Indexing blocks from #${currentBlockHeight} to #${lastBlockToIndex}`);
|
||||||
|
|
||||||
const chunkSize = 10000;
|
const chunkSize = 10000;
|
||||||
let totaIndexed = 0;
|
let totaIndexed = await blocksRepository.$blockCount(null, null);
|
||||||
let indexedThisRun = 0;
|
let indexedThisRun = 0;
|
||||||
while (currentBlockHeight >= lastBlockToIndex) {
|
while (currentBlockHeight >= lastBlockToIndex) {
|
||||||
const endBlock = Math.max(0, lastBlockToIndex, currentBlockHeight - chunkSize + 1);
|
const endBlock = Math.max(0, lastBlockToIndex, currentBlockHeight - chunkSize + 1);
|
||||||
@ -208,11 +208,9 @@ class Blocks {
|
|||||||
if (missingBlockHeights.length <= 0) {
|
if (missingBlockHeights.length <= 0) {
|
||||||
logger.debug(`No missing blocks between #${currentBlockHeight} to #${endBlock}`);
|
logger.debug(`No missing blocks between #${currentBlockHeight} to #${endBlock}`);
|
||||||
currentBlockHeight -= chunkSize;
|
currentBlockHeight -= chunkSize;
|
||||||
totaIndexed += chunkSize;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
totaIndexed += chunkSize - missingBlockHeights.length;
|
|
||||||
logger.debug(`Indexing ${missingBlockHeights.length} blocks from #${currentBlockHeight} to #${endBlock}`);
|
logger.debug(`Indexing ${missingBlockHeights.length} blocks from #${currentBlockHeight} to #${endBlock}`);
|
||||||
|
|
||||||
for (const blockHeight of missingBlockHeights) {
|
for (const blockHeight of missingBlockHeights) {
|
||||||
@ -220,7 +218,8 @@ class Blocks {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (totaIndexed % 100 === 0 || blockHeight === lastBlockToIndex) {
|
++indexedThisRun;
|
||||||
|
if (++totaIndexed % 100 === 0 || blockHeight === lastBlockToIndex) {
|
||||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
|
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
|
||||||
const blockPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
|
const blockPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
|
||||||
const progress = Math.round(totaIndexed / indexingBlockAmount * 100);
|
const progress = Math.round(totaIndexed / indexingBlockAmount * 100);
|
||||||
@ -232,8 +231,6 @@ class Blocks {
|
|||||||
const transactions = await this.$getTransactionsExtended(blockHash, block.height, true, true);
|
const transactions = await this.$getTransactionsExtended(blockHash, block.height, true, true);
|
||||||
const blockExtended = await this.$getBlockExtended(block, transactions);
|
const blockExtended = await this.$getBlockExtended(block, transactions);
|
||||||
await blocksRepository.$saveBlockInDatabase(blockExtended);
|
await blocksRepository.$saveBlockInDatabase(blockExtended);
|
||||||
++totaIndexed;
|
|
||||||
++indexedThisRun;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.err(`Something went wrong while indexing blocks.` + e);
|
logger.err(`Something went wrong while indexing blocks.` + e);
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,8 @@ class DatabaseMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (databaseSchemaVersion < 6 && isBitcoin === true) {
|
if (databaseSchemaVersion < 6 && isBitcoin === true) {
|
||||||
|
// We need to re-index the blocks table, so we nuke it
|
||||||
|
await this.$executeQuery(connection, 'TRUNCATE blocks;');
|
||||||
// Cleanup original blocks fields type
|
// Cleanup original blocks fields type
|
||||||
await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `height` integer unsigned NOT NULL DEFAULT "0"');
|
await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `height` integer unsigned NOT NULL DEFAULT "0"');
|
||||||
await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `tx_count` smallint unsigned NOT NULL DEFAULT "0"');
|
await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `tx_count` smallint unsigned NOT NULL DEFAULT "0"');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user