diff --git a/src/indexer.ts b/src/indexer.ts index ef4c314..96fa24e 100644 --- a/src/indexer.ts +++ b/src/indexer.ts @@ -218,10 +218,12 @@ const establishRpcConnection = async (): Promise => { } const migrateAndFetchDb = async (): Promise => { - // migrations die on timeout at 0015_tan_lockjaw.sql on testnet - // logger.info('Migrating DB...'); - // await MigrateDb(); - // logger.info('DB migrated.'); + if (consts.JSINFO_INDEXER_RUN_MIGRATIONS) { + // migrations die on timeout at 0015_tan_lockjaw.sql on testnet + logger.info('Migrating DB...'); + await MigrateDb(); + logger.info('DB migrated.'); + } const db = GetJsinfoDb(); logger.info('DB fetched.'); return db; diff --git a/src/indexer/indexerConsts.ts b/src/indexer/indexerConsts.ts index 11a22e6..e1788bd 100644 --- a/src/indexer/indexerConsts.ts +++ b/src/indexer/indexerConsts.ts @@ -30,6 +30,7 @@ export const JSINFO_INDEXER_EVENT_ATTRIBUTE_VALUE_MAX_LENGTH: number = parseInt( // lava_provider_bonus_rewards was 600 keys export const JSINFO_INDEXER_EVENT_ATTRIBUTE_KEY_COUNT_MAX: number = parseInt(GetEnvVar('JSINFO_INDEXER_EVENT_ATTRIBUTE_KEY_COUNT_MAX', "5000")); +export const JSINFO_INDEXER_RUN_MIGRATIONS: boolean = GetEnvVar('JSINFO_INDEXER_RUN_MIGRATIONS', "false").toLowerCase() == "true"; // Checks // Create the directory if it doesn't exist diff --git a/src/query/handlers/indexHandler.ts b/src/query/handlers/indexHandler.ts index 8afa8dc..6335d20 100644 --- a/src/query/handlers/indexHandler.ts +++ b/src/query/handlers/indexHandler.ts @@ -34,12 +34,6 @@ export const IndexHandlerOpts: RouteShorthandOptions = { allSpecs: { type: 'array', }, - qosData: { - type: 'array' - }, - data: { - type: 'array' - } } } } @@ -79,24 +73,6 @@ export async function IndexHandler(request: FastifyRequest, reply: FastifyReply) stakeSum = stakeSumQueryRes[0].stakeSum } - // - // Get "top" providers - let res4 = await QueryGetJsinfoReadDbInstance().select({ - address: JsinfoSchema.aggHourlyrelayPayments.provider, - rewardSum: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.rewardSum})`, - }).from(JsinfoSchema.aggHourlyrelayPayments). - groupBy(JsinfoSchema.aggHourlyrelayPayments.provider). - orderBy(desc(sql`sum(${JsinfoSchema.aggHourlyrelayPayments.rewardSum})`)) - let providersAddrs: string[] = [] - res4.map((provider) => { - providersAddrs.push(provider.address!) - }) - - if (providersAddrs.length == 0) { - reply.code(400).send({ error: 'Providers does not exist' }); - return; - } - // // Get top chains let topSpecs = await QueryGetJsinfoReadDbInstance().select({ @@ -117,42 +93,6 @@ export async function IndexHandler(request: FastifyRequest, reply: FastifyReply) console.log('IndexHandler empty data for topSpecs:: getChains:', getChains, 'topSpecs:', topSpecs); } - // - // Get graph with 1 day resolution - let mainChartData = {} - if (getChains.length != 0) { - mainChartData = await QueryGetJsinfoReadDbInstance().select({ - date: sql`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour}) as mydate`, - chainId: JsinfoSchema.aggHourlyrelayPayments.specId, - cuSum: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.cuSum})`, - relaySum: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`, - rewardSum: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.rewardSum})`, - }).from(JsinfoSchema.aggHourlyrelayPayments). - where( - and( - gt(sql`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour})`, sql`now() - interval '90 day'`), - inArray(JsinfoSchema.aggHourlyrelayPayments.specId, getChains) - ) - ). - groupBy(sql`${JsinfoSchema.aggHourlyrelayPayments.specId}`, sql`mydate`). - orderBy(sql`mydate DESC`) - } - - // - // QoS graph - let qosDataRaw = await QueryGetJsinfoReadDbInstance().select({ - date: sql`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour}) as mydate`, - qosSyncAvg: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.qosSyncAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`, - qosAvailabilityAvg: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.qosAvailabilityAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`, - qosLatencyAvg: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.qosLatencyAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`, - qosSyncExcAvg: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.qosSyncExcAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`, - qosAvailabilityExcAvg: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.qosAvailabilityAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`, - qosLatencyExcAv: sql`sum(${JsinfoSchema.aggHourlyrelayPayments.qosLatencyExcAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`, - }).from(JsinfoSchema.aggHourlyrelayPayments). - where(gt(sql`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour})`, sql`now() - interval '90 day'`)). - groupBy(sql`mydate`). - orderBy(sql`mydate DESC`) - return { height: latestHeight, datetime: latestDatetime, @@ -161,31 +101,5 @@ export async function IndexHandler(request: FastifyRequest, reply: FastifyReply) rewardSum: rewardSum, stakeSum: stakeSum, allSpecs: topSpecs, - qosData: FormatDates(qosDataRaw), - data: addAllChains(adjustRelayLossForMarchWeekendDowntime(FormatDates(mainChartData))), } } - -function addAllChains(mainChartData) { - const dateSums = {}; - mainChartData.forEach(data => { - if (!dateSums[data.date]) { - dateSums[data.date] = { date: data.date, chainId: "All Chains", cuSum: 0, relaySum: 0, rewardSum: null }; - } - dateSums[data.date].cuSum += Number(data.cuSum); - dateSums[data.date].relaySum += Number(data.relaySum); - }); - const newChartData = Object.values(dateSums); - return mainChartData.concat(newChartData); -} - -function adjustRelayLossForMarchWeekendDowntime(mainChartData) { - mainChartData.forEach(data => { - if (data.date === "Mar 2") { - data.relaySum = Number(data.relaySum) * 1.7; - } else if (data.date === "Mar 3") { - data.relaySum = Number(data.relaySum) * 1.6; - } - }); - return mainChartData -} \ No newline at end of file