Skip to content

Commit

Permalink
🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 committed Sep 15, 2023
1 parent 6c709db commit 8f16935
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 196 deletions.
190 changes: 95 additions & 95 deletions routes/handlers/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,6 @@ async function explorer(req, res) {
return res.status(err ? 400 : 200).json(final);
}

function getSchema(req, res, cb) {
db.select(["table_name", "column_name", "data_type"])
.from("information_schema.columns")
.where({
table_schema: "public",
})
.asCallback((err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getMmrDistributions(req, res, cb) {
queries.getDistributions(redis, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getBuildStatus(req, res, cb) {
buildStatus(db, redis, (err, status) => {
if (err) {
Expand All @@ -60,18 +37,6 @@ function getBuildStatus(req, res, cb) {
});
}

function getReplayData(req, res, cb) {
db.select(["match_id", "cluster", "replay_salt"])
.from("match_gcdata")
.whereIn("match_id", [].concat(req.query.match_id || []).slice(0, 5))
.asCallback((err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getConstants(req, res) {
return res.json(Object.keys(constants));
}
Expand All @@ -84,6 +49,60 @@ function getConstantsByResource(req, res, cb) {
return cb();
}

function getHealth(req, res, cb) {
redis.hgetall("health", (err, result) => {
if (err) {
return cb(err);
}
const response = result || {};
Object.keys(response).forEach((key) => {
response[key] = JSON.parse(response[key]);
});
if (!req.params.metric) {
return res.json(response);
}
const single = response[req.params.metric];
const healthy = single.metric < single.threshold;
return res.status(healthy ? 200 : 500).json(single);
});
}

function getItemTimings(req, res, cb) {
queries.getItemTimings(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result.rows);
});
}

function getLaneRoles(req, res, cb) {
queries.getLaneRoles(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result.rows);
});
}

function getMetadata(req, res, cb) {
queries.getMetadata(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getMmrDistributions(req, res, cb) {
queries.getDistributions(redis, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getRecordsByField(req, res, cb) {
redis.zrevrange(`records:${req.params.field}`, 0, 99, "WITHSCORES", (err, rows) => {
if (err) {
Expand All @@ -108,6 +127,18 @@ function getRecordsByField(req, res, cb) {
});
}

function getReplayData(req, res, cb) {
db.select(["match_id", "cluster", "replay_salt"])
.from("match_gcdata")
.whereIn("match_id", [].concat(req.query.match_id || []).slice(0, 5))
.asCallback((err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getRequestState(req, res, cb) {
queue.getJob(req.params.jobId, (err, job) => {
if (err) {
Expand All @@ -120,6 +151,29 @@ function getRequestState(req, res, cb) {
});
}

function getSchema(req, res, cb) {
db.select(["table_name", "column_name", "data_type"])
.from("information_schema.columns")
.where({
table_schema: "public",
})
.asCallback((err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getTeamScenarios(req, res, cb) {
queries.getTeamScenarios(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result.rows);
});
}

function requestParse(req, res) {
const matchId = req.params.match_id;
const match = {
Expand Down Expand Up @@ -161,74 +215,20 @@ function requestParse(req, res) {
return exitWithJob("invalid input");
}

function getMetadata(req, res, cb) {
queries.getMetadata(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result);
});
}

function getHealth(req, res, cb) {
redis.hgetall("health", (err, result) => {
if (err) {
return cb(err);
}
const response = result || {};
Object.keys(response).forEach((key) => {
response[key] = JSON.parse(response[key]);
});
if (!req.params.metric) {
return res.json(response);
}
const single = response[req.params.metric];
const healthy = single.metric < single.threshold;
return res.status(healthy ? 200 : 500).json(single);
});
}

function getItemTimings(req, res, cb) {
queries.getItemTimings(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result.rows);
});
}

function getLaneRoles(req, res, cb) {
queries.getLaneRoles(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result.rows);
});
}

function getTeamScenarios(req, res, cb) {
queries.getTeamScenarios(req, (err, result) => {
if (err) {
return cb(err);
}
return res.json(result.rows);
});
}

module.exports = {
explorer,
getBuildStatus,
getConstants,
getConstantsByResource,
getSchema,
getHealth,
getMmrDistributions,
getBuildStatus,
getItemTimings,
getLaneRoles,
getMetadata,
getReplayData,
getMmrDistributions,
getRecordsByField,
getReplayData,
getRequestState,
getItemTimings,
getLaneRoles,
getSchema,
getTeamScenarios,
requestParse,
};
Loading

0 comments on commit 8f16935

Please sign in to comment.