Use raw diff adjustment for diff adj table widget

This commit is contained in:
nymkappa 2022-07-09 12:35:17 +02:00 committed by softsimon
parent 4fa4088694
commit f4667c0892
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
2 changed files with 32 additions and 3 deletions

View File

@ -46,9 +46,38 @@ class DifficultyAdjustmentsRepository {
query += ` GROUP BY UNIX_TIMESTAMP(time) DIV ${86400}`; query += ` GROUP BY UNIX_TIMESTAMP(time) DIV ${86400}`;
if (descOrder === true) { if (descOrder === true) {
query += ` ORDER BY time DESC`; query += ` ORDER BY height DESC`;
} else { } else {
query += ` ORDER BY time`; query += ` ORDER BY height`;
}
try {
const [rows] = await DB.query(query);
return rows as IndexedDifficultyAdjustment[];
} catch (e) {
logger.err(`Cannot get difficulty adjustments from the database. Reason: ` + (e instanceof Error ? e.message : e));
throw e;
}
}
public async $getRawAdjustments(interval: string | null, descOrder: boolean = false): Promise<IndexedDifficultyAdjustment[]> {
interval = Common.getSqlInterval(interval);
let query = `SELECT
UNIX_TIMESTAMP(time) as time,
height as height,
difficulty as difficulty,
adjustment as adjustment
FROM difficulty_adjustments`;
if (interval) {
query += ` WHERE time BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()`;
}
if (descOrder === true) {
query += ` ORDER BY height DESC`;
} else {
query += ` ORDER BY height`;
} }
try { try {

View File

@ -734,7 +734,7 @@ class Routes {
public async $getDifficultyAdjustments(req: Request, res: Response) { public async $getDifficultyAdjustments(req: Request, res: Response) {
try { try {
const difficulty = await DifficultyAdjustmentsRepository.$getAdjustments(req.params.interval, true); const difficulty = await DifficultyAdjustmentsRepository.$getRawAdjustments(req.params.interval, true);
res.header('Pragma', 'public'); res.header('Pragma', 'public');
res.header('Cache-control', 'public'); res.header('Cache-control', 'public');
res.setHeader('Expires', new Date(Date.now() + 1000 * 300).toUTCString()); res.setHeader('Expires', new Date(Date.now() + 1000 * 300).toUTCString());