undefined committed 2023-11-29 00:05:20 +08:00
1 parent ef9f671b35
commit 14ea5bb77c
5 files changed
+23 -18

No files matched your search

+5 -5
View File
@@ -39,11 +39,11 @@ class AdminStatusHandler extends Handler {
const record = await RecordModel.stat(); const record = await RecordModel.stat();
const status = await getStatus(); const status = await getStatus();
const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([ const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([
DomainModel.coll.countDocuments(), DomainModel.coll.count(),
UserModel.coll.countDocuments(), UserModel.coll.count(),
DocumentModel.coll.countDocuments({ docType: DocumentModel.TYPE_PROBLEM }), DocumentModel.coll.count({ docType: DocumentModel.TYPE_PROBLEM }),
DocumentModel.coll.countDocuments({ docType: DocumentModel.TYPE_DISCUSSION }), DocumentModel.coll.count({ docType: DocumentModel.TYPE_DISCUSSION }),
RecordModel.coll.countDocuments(), RecordModel.coll.count(),
]); ]);
this.response.body = { this.response.body = {
record, record,
+2 -1
View File
@@ -12,8 +12,9 @@ async function paginate<T>(
filter = cursor[key]; filter = cursor[key];
break; break;
} }
const coll = db.collection(cursor.namespace.collection as any);
const [count, pageDocs] = await Promise.all([ const [count, pageDocs] = await Promise.all([
db.collection(cursor.namespace.collection as any).countDocuments(filter), Object.keys(filter).length ? coll.count(filter) : coll.countDocuments(filter),
cursor.skip((page - 1) * pageSize).limit(pageSize).toArray(), cursor.skip((page - 1) * pageSize).limit(pageSize).toArray(),
]); ]);
const numPages = Math.floor((count + pageSize - 1) / pageSize); const numPages = Math.floor((count + pageSize - 1) / pageSize);
+1
View File
@@ -986,6 +986,7 @@ export const statusText = (tdoc: Tdoc, tsdoc?: any) => (
global.Hydro.model.contest = { global.Hydro.model.contest = {
RULES, RULES,
buildContestRule,
add, add,
getListStatus, getListStatus,
getMultiStatus, getMultiStatus,
+10 -7
View File
@@ -49,14 +49,17 @@ export default class RecordModel {
@ArgMethod @ArgMethod
static async stat(domainId?: string) { static async stat(domainId?: string) {
// INFO:
// using .count() for a much better performace
// @see https://www.mongodb.com/docs/manual/reference/command/count/
const [d5min, d1h, day, week, month, year, total] = await Promise.all([ const [d5min, d1h, day, week, month, year, total] = await Promise.all([
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-5, 'minutes')) }, ...domainId ? { domainId } : {} }), RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-5, 'minutes')) }, ...domainId ? { domainId } : {} }).count(),
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'hour')) }, ...domainId ? { domainId } : {} }), RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'hour')) }, ...domainId ? { domainId } : {} }).count(),
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'day')) }, ...domainId ? { domainId } : {} }), RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'day')) }, ...domainId ? { domainId } : {} }).count(),
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'week')) }, ...domainId ? { domainId } : {} }), RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'week')) }, ...domainId ? { domainId } : {} }).count(),
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'month')) }, ...domainId ? { domainId } : {} }), RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'month')) }, ...domainId ? { domainId } : {} }).count(),
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'year')) }, ...domainId ? { domainId } : {} }), RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'year')) }, ...domainId ? { domainId } : {} }).count(),
RecordModel.coll.countDocuments(domainId ? { domainId } : {}), RecordModel.coll.find(domainId ? { domainId } : {}).count(),
]); ]);
return { return {
d5min, d1h, day, week, month, year, total, d5min, d1h, day, week, month, year, total,
+5 -5
View File
@@ -18,11 +18,11 @@ export async function feedback(): Promise<[string, StatusUpdate]> {
const [mid, $update, inf] = await sysinfo.update(); const [mid, $update, inf] = await sysinfo.update();
const [installId, name, url] = system.getMany(['installid', 'server.name', 'server.url']); const [installId, name, url] = system.getMany(['installid', 'server.name', 'server.url']);
const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([ const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([
domain.coll.countDocuments(), domain.coll.count(),
user.coll.countDocuments(), user.coll.count(),
document.coll.countDocuments({ docType: document.TYPE_PROBLEM }), document.coll.count({ docType: document.TYPE_PROBLEM }),
document.coll.countDocuments({ docType: document.TYPE_DISCUSSION }), document.coll.count({ docType: document.TYPE_DISCUSSION }),
record.coll.countDocuments(), record.coll.count(),
]); ]);
const info: Record<string, any> = { const info: Record<string, any> = {
mid: mid.toString(), mid: mid.toString(),