mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: remove deprecated cursor.count call
This commit is contained in:
3 files changed
+14
-44
No files matched your search
@@ -1,10 +1,6 @@
|
||||
import { Context } from '../context';
|
||||
import { PRIV } from '../model/builtin';
|
||||
import * as DocumentModel from '../model/document';
|
||||
import DomainModel from '../model/domain';
|
||||
import RecordModel from '../model/record';
|
||||
import * as SettingModel from '../model/setting';
|
||||
import UserModel from '../model/user';
|
||||
import db from '../service/db';
|
||||
import { Handler } from '../service/server';
|
||||
|
||||
@@ -71,45 +67,22 @@ class StatusHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
class AdminStatusHandler extends Handler {
|
||||
async get() {
|
||||
const record = await RecordModel.stat();
|
||||
const status = await getStatus();
|
||||
const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([
|
||||
DomainModel.coll.count(),
|
||||
UserModel.coll.count(),
|
||||
DocumentModel.coll.count({ docType: DocumentModel.TYPE_PROBLEM }),
|
||||
DocumentModel.coll.count({ docType: DocumentModel.TYPE_DISCUSSION }),
|
||||
RecordModel.coll.count(),
|
||||
]);
|
||||
this.response.body = {
|
||||
record,
|
||||
status,
|
||||
domainCount,
|
||||
userCount,
|
||||
problemCount,
|
||||
discussionCount,
|
||||
recordCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class StatusUpdateHandler extends Handler {
|
||||
async post(args) {
|
||||
this.checkPriv(PRIV.PRIV_JUDGE);
|
||||
args.type = 'judge';
|
||||
args.updateAt = new Date();
|
||||
return coll.updateOne(
|
||||
await coll.updateOne(
|
||||
{ mid: args.mid, type: 'judge' },
|
||||
{ $set: args },
|
||||
{ upsert: true },
|
||||
);
|
||||
this.response.body = { ok: 1 };
|
||||
}
|
||||
}
|
||||
|
||||
export async function apply(ctx: Context) {
|
||||
ctx.Route('status', '/status', StatusHandler);
|
||||
ctx.Route('status_admin', '/.status', AdminStatusHandler);
|
||||
ctx.Route('status_update', '/status/update', StatusUpdateHandler);
|
||||
await db.ensureIndexes(coll, { name: 'expire', key: { updateAt: 1 }, expireAfterSeconds: 24 * 2600 });
|
||||
}
|
||||
@@ -62,17 +62,14 @@ export default class RecordModel {
|
||||
|
||||
@ArgMethod
|
||||
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([
|
||||
RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-5, 'minutes')) }, ...domainId ? { domainId } : {} }).count(),
|
||||
RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'hour')) }, ...domainId ? { domainId } : {} }).count(),
|
||||
RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'day')) }, ...domainId ? { domainId } : {} }).count(),
|
||||
RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'week')) }, ...domainId ? { domainId } : {} }).count(),
|
||||
RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'month')) }, ...domainId ? { domainId } : {} }).count(),
|
||||
RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'year')) }, ...domainId ? { domainId } : {} }).count(),
|
||||
RecordModel.coll.find(domainId ? { domainId } : {}).count(),
|
||||
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-5, 'minutes')) }, ...domainId ? { domainId } : {} }),
|
||||
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'hour')) }, ...domainId ? { domainId } : {} }),
|
||||
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'day')) }, ...domainId ? { domainId } : {} }),
|
||||
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'week')) }, ...domainId ? { domainId } : {} }),
|
||||
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'month')) }, ...domainId ? { domainId } : {} }),
|
||||
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'year')) }, ...domainId ? { domainId } : {} }),
|
||||
domainId ? RecordModel.coll.countDocuments({ domainId }) : RecordModel.coll.estimatedDocumentCount(),
|
||||
]);
|
||||
return {
|
||||
d5min, d1h, day, week, month, year, total,
|
||||
|
||||
@@ -23,11 +23,11 @@ export async function feedback(): Promise<[string, StatusUpdate]> {
|
||||
const [mid, $update, inf] = await sysinfo.update();
|
||||
const [installId, name, url] = system.getMany(['installid', 'server.name', 'server.url']);
|
||||
const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([
|
||||
domain.coll.count(),
|
||||
user.coll.count(),
|
||||
document.coll.count({ docType: document.TYPE_PROBLEM }),
|
||||
document.coll.count({ docType: document.TYPE_DISCUSSION }),
|
||||
record.coll.count(),
|
||||
domain.coll.estimatedDocumentCount(),
|
||||
user.coll.estimatedDocumentCount(),
|
||||
document.coll.countDocuments({ docType: document.TYPE_PROBLEM }),
|
||||
document.coll.countDocuments({ docType: document.TYPE_DISCUSSION }),
|
||||
record.coll.estimatedDocumentCount(),
|
||||
]);
|
||||
const info: Record<string, any> = {
|
||||
mid: mid.toString(),
|
||||
|
||||
Reference in new issue
Block a user