feat: add db query timeout option

This commit is contained in:
Axel Cocat 2022-03-05 15:32:03 +01:00
parent 4b8dc1fa1c
commit ab5dcd3640
6 changed files with 105 additions and 67 deletions

View file

@ -54,21 +54,23 @@ export class IndexController {
}
const db = this.armory.getCharactersDb(realm.name);
const conn = await db.getConnection();
if (!(realm.name in this.charsetCache)) {
let [rows, fields] = await db.query(`
SELECT CCSA.character_set_name FROM information_schema.\`TABLES\` T,
information_schema.\`COLLATION_CHARACTER_SET_APPLICABILITY\` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "${conn.config.database}"
AND T.table_name = "characters"
`);
let [rows, fields] = await db.query({
sql: `
SELECT CCSA.character_set_name FROM information_schema.\`TABLES\` T,
information_schema.\`COLLATION_CHARACTER_SET_APPLICABILITY\` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "${(await db.getConnection()).config.database}"
AND T.table_name = "characters"
`,
timeout: this.armory.config.dbQueryTimeout,
});
this.charsetCache[realm.name] = rows[0].character_set_name;
}
const charSet = this.charsetCache[realm.name];
let ssp = new DataTablesSsp(req.query, conn, "characters", "guid", [
let ssp = new DataTablesSsp(req.query, db, "characters", "guid", [
{ name: "name", collation: `${charSet}_general_ci` },
{ table: "guild", name: "name" },
{ name: "level" },
@ -89,7 +91,7 @@ export class IndexController {
const result = await ssp
.where("`deleteInfos_Account` IS NULL")
.run();
.run(this.armory.config.dbQueryTimeout);
(result as any).realm = realm.name;
res.json(result);