Skip to content

Commit 60c6196

Browse files
committed
Clean up repository statistics page
1 parent fd865ee commit 60c6196

File tree

6 files changed

+787
-259
lines changed

6 files changed

+787
-259
lines changed

express/backend/package-lock.json

Lines changed: 45 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

express/backend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
"archiver": "^5.3.0",
1919
"axios": "^0.22.0",
2020
"cors": "^2.8.5",
21-
"cron": "^1.8.2",
21+
"cron": "^4.3.4",
2222
"express": "^4.17.1",
2323
"fs-extra": "^10.0.0",
2424
"libsodium-wrappers": "^0.7.15",
25+
"luxon": "~3.7.0",
2526
"mkdirp": "^1.0.4",
2627
"mongodb": "^4.1.3",
2728
"node-cache": "^5.1.2",
@@ -38,6 +39,7 @@
3839
"@types/express": "^4.17.13",
3940
"@types/fs-extra": "^9.0.13",
4041
"@types/libsodium-wrappers": "^0.7.14",
42+
"@types/luxon": "^3.7.1",
4143
"@types/mkdirp": "^1.0.2",
4244
"@types/mongodb": "^4.0.7",
4345
"@types/node": "^16.10.3",

express/backend/src/api/statistics.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ router.get("/api/statistics", async function (req, res) {
8888
const db = await dbConnect();
8989
const repos = db.gitHubRepos();
9090

91+
const filters = Object.keys(req.query).filter(
92+
(key) =>
93+
key !== "stats" &&
94+
typeof req.query[key] === "string" &&
95+
availableFields.hasOwnProperty(key),
96+
) as (keyof typeof availableFields)[];
97+
9198
const statsToInclude =
9299
((req.query.stats as string)?.split(
93100
",",
94101
) as (keyof typeof availableFields)[]) ?? [];
102+
statsToInclude.push(...filters);
95103

96104
const pipeline: Document[] = [
97105
{
@@ -100,7 +108,7 @@ router.get("/api/statistics", async function (req, res) {
100108
},
101109
},
102110
];
103-
if (statsToInclude.includes("publishState")) {
111+
if (statsToInclude.includes("publishState") || req.query.publishState) {
104112
pipeline.push({
105113
$lookup: {
106114
as: "repo-adapters",
@@ -124,11 +132,25 @@ router.get("/api/statistics", async function (req, res) {
124132
$project,
125133
});
126134

135+
if (filters.length) {
136+
const $match: Record<string, any> = {};
137+
for (const field of filters) {
138+
$match[field] = req.query[field];
139+
}
140+
pipeline.push({
141+
$match,
142+
});
143+
}
144+
127145
const stream = repos.aggregate(pipeline).stream();
128146

129147
const stats = new Map<string, Map<string, number>>();
130148
for await (const doc of stream) {
131149
for (const [key, value] of Object.entries(doc)) {
150+
if (req.query[key]) {
151+
// skip stats that are used as filter
152+
continue;
153+
}
132154
if (!stats.has(key)) {
133155
stats.set(key, new Map<string, number>());
134156
}

0 commit comments

Comments
 (0)