Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLUE-206 Revert to the original index applied in the tables due to slow db queries #59

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 12 additions & 12 deletions src/Data/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as Cycles from './Cycles'
import {
getCurrentCycleCounter,
currentCycleDuration,

Check warning on line 8 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

'currentCycleDuration' is defined but never used

Check warning on line 8 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

'currentCycleDuration' is defined but never used
processCycles,
validateCycle,
validateCycleData,
Expand Down Expand Up @@ -525,11 +525,11 @@
dataSenders.set(sender.nodeInfo.publicKey, sender)
}

async function syncFromNetworkConfig(): Promise<any> {

Check warning on line 528 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

Unexpected any. Specify a different type

Check warning on line 528 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

Unexpected any. Specify a different type
try {
// Define the query function to get the network config from a node
const queryFn = async (node): Promise<object> => {
const REQUEST_NETCONFIG_TIMEOUT_SECOND = 2 // 2s timeout
const REQUEST_NETCONFIG_TIMEOUT_SECOND = 3 // 3s timeout
try {
const response = await P2P.getJson(
`http://${node.ip}:${node.port}/netconfig`,
Expand Down Expand Up @@ -566,17 +566,17 @@
configChangeMaxCyclesToKeep,
maxCyclesShardDataToKeep,
} = tallyItem.value.config.stateManager
const devPublicKeys = tallyItem.value.config.debug.devPublicKeys
const devPublicKey =
devPublicKeys &&
Object.keys(devPublicKeys).length >= 3 &&
Object.keys(devPublicKeys).find((key) => devPublicKeys[key] === 3)
if (
devPublicKey &&
typeof devPublicKey === typeof config.DevPublicKey &&
devPublicKey !== config.DevPublicKey
)
updateConfig({ DevPublicKey: devPublicKey })
// const devPublicKeys = tallyItem.value.config.debug.devPublicKeys
// const devPublicKey =
// devPublicKeys &&
// Object.keys(devPublicKeys).length >= 3 &&
// Object.keys(devPublicKeys).find((key) => devPublicKeys[key] === 3)
// if (
// devPublicKey &&
// typeof devPublicKey === typeof config.DevPublicKey &&
// devPublicKey !== config.DevPublicKey
// )
// updateConfig({ DevPublicKey: devPublicKey })
if (
!Utils.isUndefined(newPOQReceipt) &&
typeof newPOQReceipt === typeof config.newPOQReceipt &&
Expand Down Expand Up @@ -1505,7 +1505,7 @@
}
} else {
if (totalSavedReceiptsCount >= totalReceipts) {
const res: any = await getTotalDataFromArchivers()

Check warning on line 1508 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

Unexpected any. Specify a different type

Check warning on line 1508 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

Unexpected any. Specify a different type
if (res && res.totalReceipts > 0) {
if (res.totalReceipts > totalReceipts) totalReceipts = res.totalReceipts
if (res.totalCycles > totalCycles) totalCycles = res.totalCycles
Expand Down Expand Up @@ -1625,7 +1625,7 @@
}
}
Logger.mainLogger.debug(`Downloading Original-Txs from ${start} to ${end}`)
const res: any = await queryFromArchivers(

Check warning on line 1628 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

Unexpected any. Specify a different type

Check warning on line 1628 in src/Data/Data.ts

View workflow job for this annotation

GitHub Actions / ci / QA merge checks

Unexpected any. Specify a different type
RequestDataType.ORIGINALTX,
{
start: start,
Expand Down
19 changes: 7 additions & 12 deletions src/dbstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export const initializeDB = async (config: Config): Promise<void> => {
'CREATE TABLE if not exists `transactions` (`txId` TEXT NOT NULL UNIQUE PRIMARY KEY, `appReceiptId` TEXT, `timestamp` BIGINT NOT NULL, `cycleNumber` NUMBER NOT NULL, `data` JSON NOT NULL, `originalTxData` JSON NOT NULL)'
)
await db.runCreate(
'CREATE INDEX if not exists `transactions_cycleNumber` ON `transactions` (`cycleNumber` ASC)'
)
await db.runCreate(
'CREATE INDEX if not exists `transactions_timestamp` ON `transactions` (`timestamp` ASC)'
'CREATE INDEX if not exists `transactions_idx` ON `transactions` (`cycleNumber` DESC, `timestamp` DESC)'
)
await db.runCreate(
'CREATE INDEX if not exists `transactions_appReceiptId_idx` ON `transactions` (`appReceiptId`)'
Expand All @@ -22,22 +19,20 @@ export const initializeDB = async (config: Config): Promise<void> => {
await db.runCreate(
'CREATE TABLE if not exists `accounts` (`accountId` TEXT NOT NULL UNIQUE PRIMARY KEY, `data` JSON NOT NULL, `timestamp` BIGINT NOT NULL, `hash` TEXT NOT NULL, `cycleNumber` NUMBER NOT NULL, `isGlobal` BOOLEAN NOT NULL)'
)
await db.runCreate('CREATE INDEX if not exists `accounts_cycleNumber` ON `accounts` (`cycleNumber` ASC)')
await db.runCreate('CREATE INDEX if not exists `accounts_timestamp` ON `accounts` (`timestamp` ASC)')
await db.runCreate(
'CREATE INDEX if not exists `accounts_idx` ON `accounts` (`cycleNumber` DESC, `timestamp` DESC)'
)
await db.runCreate(
'CREATE TABLE if not exists `receipts` (`receiptId` TEXT NOT NULL UNIQUE PRIMARY KEY, `tx` JSON NOT NULL, `cycle` NUMBER NOT NULL, `timestamp` BIGINT NOT NULL, `beforeStateAccounts` JSON, `accounts` JSON NOT NULL, `appliedReceipt` JSON NOT NULL, `appReceiptData` JSON, `executionShardKey` TEXT NOT NULL, `globalModification` BOOLEAN NOT NULL)'
)
await db.runCreate('CREATE INDEX if not exists `receipts_cycle` ON `receipts` (`cycle` ASC)')
await db.runCreate('CREATE INDEX if not exists `receipts_timestamp` ON `receipts` (`timestamp` ASC)')

await db.runCreate('CREATE INDEX if not exists `receipts_idx` ON `receipts` (`cycle` ASC, `timestamp` ASC)')
await db.runCreate(
'CREATE TABLE if not exists `originalTxsData` (`txId` TEXT NOT NULL, `timestamp` BIGINT NOT NULL, `cycle` NUMBER NOT NULL, `originalTxData` JSON NOT NULL, PRIMARY KEY (`txId`, `timestamp`))'
)
await db.runCreate('CREATE INDEX if not exists `originalTxsData_cycle` ON `originalTxsData` (`cycle` ASC)')
await db.runCreate(
'CREATE INDEX if not exists `originalTxsData_timestamp` ON `originalTxsData` (`timestamp` ASC)'
'CREATE INDEX if not exists `originalTxsData_idx` ON `originalTxsData` (`cycle` ASC, `timestamp` ASC)'
)
await db.runCreate('CREATE INDEX if not exists `originalTxsData_txId` ON `originalTxsData` (`txId`)')
await db.runCreate('CREATE INDEX if not exists `originalTxsData_txId_idx` ON `originalTxsData` (`txId`)')
}

export const closeDatabase = async (): Promise<void> => {
Expand Down
Loading