Set db connection to UTC - Fix hashrate indexing
This commit is contained in:
@@ -8,7 +8,7 @@ class BlocksRepository {
|
||||
* Save indexed block data in the database
|
||||
*/
|
||||
public async $saveBlockInDatabase(block: BlockExtended) {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
|
||||
try {
|
||||
const query = `INSERT INTO blocks(
|
||||
@@ -70,7 +70,7 @@ class BlocksRepository {
|
||||
return [];
|
||||
}
|
||||
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows]: any[] = await connection.query(`
|
||||
SELECT height
|
||||
@@ -116,7 +116,7 @@ class BlocksRepository {
|
||||
|
||||
query += ` GROUP by pools.id`;
|
||||
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.query(query, params);
|
||||
connection.release();
|
||||
@@ -154,7 +154,7 @@ class BlocksRepository {
|
||||
}
|
||||
|
||||
// logger.debug(query);
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.query(query, params);
|
||||
connection.release();
|
||||
@@ -194,7 +194,7 @@ class BlocksRepository {
|
||||
query += ` blockTimestamp BETWEEN FROM_UNIXTIME('${from}') AND FROM_UNIXTIME('${to}')`;
|
||||
|
||||
// logger.debug(query);
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.query(query, params);
|
||||
connection.release();
|
||||
@@ -217,7 +217,7 @@ class BlocksRepository {
|
||||
LIMIT 1;`;
|
||||
|
||||
// logger.debug(query);
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows]: any[] = await connection.query(query);
|
||||
connection.release();
|
||||
@@ -253,7 +253,7 @@ class BlocksRepository {
|
||||
LIMIT 10`;
|
||||
|
||||
// logger.debug(query);
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.query(query, params);
|
||||
connection.release();
|
||||
@@ -274,7 +274,7 @@ class BlocksRepository {
|
||||
* Get one block by height
|
||||
*/
|
||||
public async $getBlockByHeight(height: number): Promise<object | null> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows]: any[] = await connection.query(`
|
||||
SELECT *, UNIX_TIMESTAMP(blocks.blockTimestamp) as blockTimestamp,
|
||||
@@ -305,7 +305,7 @@ class BlocksRepository {
|
||||
public async $getBlocksDifficulty(interval: string | null): Promise<object[]> {
|
||||
interval = Common.getSqlInterval(interval);
|
||||
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
|
||||
// :D ... Yeah don't ask me about this one https://stackoverflow.com/a/40303162
|
||||
// Basically, using temporary user defined fields, we are able to extract all
|
||||
@@ -356,7 +356,7 @@ class BlocksRepository {
|
||||
}
|
||||
|
||||
public async $getOldestIndexedBlockHeight(): Promise<number> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows]: any[] = await connection.query(`SELECT MIN(height) as minHeight FROM blocks`);
|
||||
connection.release();
|
||||
|
||||
@@ -20,9 +20,9 @@ class HashratesRepository {
|
||||
}
|
||||
query = query.slice(0, -1);
|
||||
|
||||
const connection = await DB.pool.getConnection();
|
||||
let connection;
|
||||
try {
|
||||
// logger.debug(query);
|
||||
connection = await DB.getConnection();
|
||||
await connection.query(query);
|
||||
connection.release();
|
||||
} catch (e: any) {
|
||||
@@ -35,18 +35,16 @@ class HashratesRepository {
|
||||
public async $getNetworkDailyHashrate(interval: string | null): Promise<any[]> {
|
||||
interval = Common.getSqlInterval(interval);
|
||||
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
|
||||
let query = `SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp, avg_hashrate as avgHashrate
|
||||
FROM hashrates`;
|
||||
|
||||
if (interval) {
|
||||
query += ` WHERE hashrate_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()
|
||||
AND hashrates.type = 'daily'
|
||||
AND pool_id IS NULL`;
|
||||
AND hashrates.type = 'daily'`;
|
||||
} else {
|
||||
query += ` WHERE hashrates.type = 'daily'
|
||||
AND pool_id IS NULL`;
|
||||
query += ` WHERE hashrates.type = 'daily'`;
|
||||
}
|
||||
|
||||
query += ` ORDER by hashrate_timestamp`;
|
||||
@@ -64,9 +62,12 @@ class HashratesRepository {
|
||||
}
|
||||
|
||||
public async $getWeeklyHashrateTimestamps(): Promise<number[]> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
|
||||
const query = `SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp FROM hashrates where type = 'weekly' GROUP BY hashrate_timestamp`;
|
||||
const query = `SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp
|
||||
FROM hashrates
|
||||
WHERE type = 'weekly'
|
||||
GROUP BY hashrate_timestamp`;
|
||||
|
||||
try {
|
||||
const [rows]: any[] = await connection.query(query);
|
||||
@@ -86,7 +87,7 @@ class HashratesRepository {
|
||||
public async $getPoolsWeeklyHashrate(interval: string | null): Promise<any[]> {
|
||||
interval = Common.getSqlInterval(interval);
|
||||
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
const topPoolsId = (await PoolsRepository.$getPoolsInfo('1w')).map((pool) => pool.poolId);
|
||||
|
||||
let query = `SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp, avg_hashrate as avgHashrate, share, pools.name as poolName
|
||||
@@ -120,7 +121,7 @@ class HashratesRepository {
|
||||
* Returns a pool hashrate history
|
||||
*/
|
||||
public async $getPoolWeeklyHashrate(poolId: number): Promise<any[]> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
|
||||
// Find hashrate boundaries
|
||||
let query = `SELECT MIN(hashrate_timestamp) as firstTimestamp, MAX(hashrate_timestamp) as lastTimestamp
|
||||
@@ -163,7 +164,7 @@ class HashratesRepository {
|
||||
}
|
||||
|
||||
public async $setLatestRunTimestamp(key: string, val: any = null) {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
const query = `UPDATE state SET number = ? WHERE name = ?`;
|
||||
|
||||
try {
|
||||
@@ -175,7 +176,7 @@ class HashratesRepository {
|
||||
}
|
||||
|
||||
public async $getLatestRunTimestamp(key: string): Promise<number> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
const query = `SELECT number FROM state WHERE name = ?`;
|
||||
|
||||
try {
|
||||
|
||||
@@ -8,7 +8,7 @@ class PoolsRepository {
|
||||
* Get all pools tagging info
|
||||
*/
|
||||
public async $getPools(): Promise<PoolTag[]> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
const [rows] = await connection.query('SELECT id, name, addresses, regexes FROM pools;');
|
||||
connection.release();
|
||||
return <PoolTag[]>rows;
|
||||
@@ -18,7 +18,7 @@ class PoolsRepository {
|
||||
* Get unknown pool tagging info
|
||||
*/
|
||||
public async $getUnknownPool(): Promise<PoolTag> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
const [rows] = await connection.query('SELECT id, name FROM pools where name = "Unknown"');
|
||||
connection.release();
|
||||
return <PoolTag>rows[0];
|
||||
@@ -42,7 +42,7 @@ class PoolsRepository {
|
||||
ORDER BY COUNT(height) DESC`;
|
||||
|
||||
// logger.debug(query);
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.query(query);
|
||||
connection.release();
|
||||
@@ -64,7 +64,7 @@ class PoolsRepository {
|
||||
LEFT JOIN blocks on pools.id = blocks.pool_id AND blocks.blockTimestamp BETWEEN FROM_UNIXTIME(?) AND FROM_UNIXTIME(?)
|
||||
GROUP BY pools.id`;
|
||||
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.query(query, [from, to]);
|
||||
connection.release();
|
||||
@@ -87,7 +87,7 @@ class PoolsRepository {
|
||||
WHERE pools.id = ?`;
|
||||
|
||||
// logger.debug(query);
|
||||
const connection = await DB.pool.getConnection();
|
||||
const connection = await DB.getConnection();
|
||||
try {
|
||||
const [rows] = await connection.query(query, [poolId]);
|
||||
connection.release();
|
||||
|
||||
Reference in New Issue
Block a user