-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
59 lines (47 loc) · 1.38 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const mysql = require('mysql2');
const dbconfig = require('/Users/changjie.lin/work/gh/db_checker/dbconfig');
let conf = dbconfig.logs;
let iCount = [];
for (let i = 0; i < 10; i++) {
iCount[i] = 0;
}
const zeroPad = (num, places) => String(num).padStart(places, '0');
const countOneDB = async (idx) => {
try {
const padLen = 8;
let dbName = 'shopee_incentive_trigger_log_db_' + zeroPad(idx, padLen);
conf.database = dbName;
const pool = mysql.createPool(conf);
let tabName;
for (let j = 0; j < 1000; j++) {
let num = idx * 1000 + j;
tabName = 'incentive_trigger_tab_' + zeroPad(num, padLen);
const sql = `SELECT COUNT(*) as count FROM ${tabName}`;
const promisePool = pool.promise();
let [result, fields] = await promisePool.query(sql);
// console.log("DB #" + idx + " Table #" + j);
// console.log(result[0].count);
iCount[idx] += result[0].count;
}
await pool.end();
} catch (error) {
console.log("ERROR: ", error.message);
}
}
async function main() {
const promises = [];
for (let i = 0; i < 10; i++) {
promises.push(countOneDB(i));
}
try {
await Promise.all(promises);
} catch (error) {
console.log("ERROR: ", error.message);
}
let allCount = 0;
for (let i = 0; i < iCount.length; i++) {
allCount += iCount[i];
}
console.log("Total Count =", allCount);
}
main()