mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-10 01:24:08 +02:00
feat: cache server stat
This commit is contained in:
+14
-2
@@ -143,7 +143,17 @@ export default async function start() {
|
|||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let stat: any = {};
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
stat = {};
|
||||||
|
}, 1000 * 60 * 60);
|
||||||
|
|
||||||
apiRouter.get("/stat", async (_, res) => {
|
apiRouter.get("/stat", async (_, res) => {
|
||||||
|
if (stat.nbRepositories) {
|
||||||
|
res.json(stat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const [nbRepositories, users, nbPageViews, nbPullRequests] =
|
const [nbRepositories, users, nbPageViews, nbPullRequests] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
AnonymizedRepositoryModel.estimatedDocumentCount(),
|
AnonymizedRepositoryModel.estimatedDocumentCount(),
|
||||||
@@ -158,12 +168,14 @@ export default async function start() {
|
|||||||
AnonymizedPullRequestModel.estimatedDocumentCount(),
|
AnonymizedPullRequestModel.estimatedDocumentCount(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
res.json({
|
stat = {
|
||||||
nbRepositories,
|
nbRepositories,
|
||||||
nbUsers: users.length,
|
nbUsers: users.length,
|
||||||
nbPageViews: nbPageViews[0]?.total || 0,
|
nbPageViews: nbPageViews[0]?.total || 0,
|
||||||
nbPullRequests,
|
nbPullRequests,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
res.json(stat);
|
||||||
});
|
});
|
||||||
|
|
||||||
// web view
|
// web view
|
||||||
|
|||||||
Reference in New Issue
Block a user