From bb0fd78f2857e0568cfafa7fe3f9d292f4b05e68 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Thu, 24 Mar 2022 19:44:22 +0900 Subject: [PATCH] Added slug into `pools` table --- backend/src/api/database-migration.ts | 6 +++++- backend/src/api/pools-parser.ts | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 20519cbf2..3978a7d85 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -6,7 +6,7 @@ import logger from '../logger'; const sleep = (ms: number) => new Promise(res => setTimeout(res, ms)); class DatabaseMigration { - private static currentVersion = 16; + private static currentVersion = 17; private queryTimeout = 120000; private statisticsAddedIndexed = false; @@ -180,6 +180,10 @@ class DatabaseMigration { await this.$executeQuery(connection, 'TRUNCATE hashrates;'); // Need to re-index because we changed timestamps } + if (databaseSchemaVersion < 17 && isBitcoin === true) { + await this.$executeQuery(connection, 'ALTER TABLE `pools` ADD `slug` CHAR(50) NULL'); + } + connection.release(); } catch (e) { connection.release(); diff --git a/backend/src/api/pools-parser.ts b/backend/src/api/pools-parser.ts index ff70c3cb9..5428f931d 100644 --- a/backend/src/api/pools-parser.ts +++ b/backend/src/api/pools-parser.ts @@ -8,6 +8,7 @@ interface Pool { link: string; regexes: string[]; addresses: string[]; + slug: string; } class PoolsParser { @@ -42,6 +43,7 @@ class PoolsParser { 'link': (coinbaseTags[i][1]).link, 'regexes': [coinbaseTags[i][0]], 'addresses': [], + 'slug': '' }); } logger.debug('Parse payout_addresses'); @@ -52,6 +54,7 @@ class PoolsParser { 'link': (addressesTags[i][1]).link, 'regexes': [], 'addresses': [addressesTags[i][0]], + 'slug': '' }); } @@ -90,14 +93,15 @@ class PoolsParser { } const finalPoolName = poolNames[i].replace(`'`, `''`); // To support single quote in names when doing db queries + const slug = poolsJson['slugs'][poolNames[i]]; if (existingPools.find((pool) => pool.name === poolNames[i]) !== undefined) { - logger.debug(`Update '${finalPoolName}' mining pool`); finalPoolDataUpdate.push({ 'name': finalPoolName, 'link': match[0].link, 'regexes': allRegexes, 'addresses': allAddresses, + 'slug': slug }); } else { logger.debug(`Add '${finalPoolName}' mining pool`); @@ -106,6 +110,7 @@ class PoolsParser { 'link': match[0].link, 'regexes': allRegexes, 'addresses': allAddresses, + 'slug': slug }); } } @@ -126,7 +131,8 @@ class PoolsParser { updateQueries.push(` UPDATE pools SET name='${finalPoolDataUpdate[i].name}', link='${finalPoolDataUpdate[i].link}', - regexes='${JSON.stringify(finalPoolDataUpdate[i].regexes)}', addresses='${JSON.stringify(finalPoolDataUpdate[i].addresses)}' + regexes='${JSON.stringify(finalPoolDataUpdate[i].regexes)}', addresses='${JSON.stringify(finalPoolDataUpdate[i].addresses)}', + slug='${finalPoolDataUpdate[i].slug}' WHERE name='${finalPoolDataUpdate[i].name}' ;`); } @@ -156,11 +162,17 @@ class PoolsParser { try { const [rows]: any[] = await connection.query({ sql: 'SELECT name from pools where name="Unknown"', timeout: 120000 }); if (rows.length === 0) { - logger.debug('Manually inserting "Unknown" mining pool into the databse'); await connection.query({ sql: `INSERT INTO pools(name, link, regexes, addresses) - VALUES("Unknown", "https://learnmeabitcoin.com/technical/coinbase-transaction", "[]", "[]"); + VALUES("Unknown", "https://learnmeabitcoin.com/technical/coinbase-transaction", "[]", "[]", "unknown"); `}); + } else { + await connection.query(`UPDATE pools + SET name='Unknown', link='https://learnmeabitcoin.com/technical/coinbase-transaction', + regexes='[]', addresses='[]', + slug='unknown' + WHERE name='Unknown' + `) } } catch (e) { logger.err('Unable to insert "Unknown" mining pool');