optimize block audit scores db query

This commit is contained in:
Mononaut
2022-11-24 17:03:54 +09:00
parent 5fc3b8b70c
commit de04914851
4 changed files with 20 additions and 43 deletions

View File

@@ -93,6 +93,20 @@ class BlocksAuditRepositories {
throw e;
}
}
public async $getBlockAuditScores(maxHeight: number, minHeight: number): Promise<AuditScore[]> {
try {
const [rows]: any[] = await DB.query(
`SELECT hash, match_rate as matchRate
FROM blocks_audits
WHERE blocks_audits.height BETWEEN ? AND ?
`, [minHeight, maxHeight]);
return rows;
} catch (e: any) {
logger.err(`Cannot fetch block audit from db. Reason: ` + (e instanceof Error ? e.message : e));
throw e;
}
}
}
export default new BlocksAuditRepositories();