Index new hashrates once every 24 hours
This commit is contained in:
@@ -281,6 +281,13 @@ class BlocksRepository {
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
public async $getOldestIndexedBlockHeight(): Promise<number> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const [rows]: any[] = await connection.query(`SELECT MIN(height) as minHeight FROM blocks`);
|
||||
connection.release();
|
||||
return rows[0].minHeight;
|
||||
}
|
||||
}
|
||||
|
||||
export default new BlocksRepository();
|
||||
|
||||
@@ -43,11 +43,28 @@ class HashratesRepository {
|
||||
query += ` WHERE hashrate_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()`;
|
||||
}
|
||||
|
||||
query += ` ORDER by hashrate_timestamp DESC`;
|
||||
|
||||
const [rows]: any[] = await connection.query(query);
|
||||
connection.release();
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
public async $setLatestRunTimestamp() {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const query = `UPDATE state SET number = ? WHERE name = 'last_hashrates_indexing'`;
|
||||
await connection.query<any>(query, [Math.round(new Date().getTime() / 1000)]);
|
||||
connection.release();
|
||||
}
|
||||
|
||||
public async $getLatestRunTimestamp(): Promise<number> {
|
||||
const connection = await DB.pool.getConnection();
|
||||
const query = `SELECT number FROM state WHERE name = 'last_hashrates_indexing'`;
|
||||
const [rows] = await connection.query<any>(query);
|
||||
connection.release();
|
||||
return rows[0]['number'];
|
||||
}
|
||||
}
|
||||
|
||||
export default new HashratesRepository();
|
||||
|
||||
Reference in New Issue
Block a user