mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01: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 { Context } from '../context';
|
||||||
import { PRIV } from '../model/builtin';
|
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 * as SettingModel from '../model/setting';
|
||||||
import UserModel from '../model/user';
|
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
import { Handler } from '../service/server';
|
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 {
|
class StatusUpdateHandler extends Handler {
|
||||||
async post(args) {
|
async post(args) {
|
||||||
this.checkPriv(PRIV.PRIV_JUDGE);
|
this.checkPriv(PRIV.PRIV_JUDGE);
|
||||||
args.type = 'judge';
|
args.type = 'judge';
|
||||||
args.updateAt = new Date();
|
args.updateAt = new Date();
|
||||||
return coll.updateOne(
|
await coll.updateOne(
|
||||||
{ mid: args.mid, type: 'judge' },
|
{ mid: args.mid, type: 'judge' },
|
||||||
{ $set: args },
|
{ $set: args },
|
||||||
{ upsert: true },
|
{ upsert: true },
|
||||||
);
|
);
|
||||||
|
this.response.body = { ok: 1 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apply(ctx: Context) {
|
export async function apply(ctx: Context) {
|
||||||
ctx.Route('status', '/status', StatusHandler);
|
ctx.Route('status', '/status', StatusHandler);
|
||||||
ctx.Route('status_admin', '/.status', AdminStatusHandler);
|
|
||||||
ctx.Route('status_update', '/status/update', StatusUpdateHandler);
|
ctx.Route('status_update', '/status/update', StatusUpdateHandler);
|
||||||
await db.ensureIndexes(coll, { name: 'expire', key: { updateAt: 1 }, expireAfterSeconds: 24 * 2600 });
|
await db.ensureIndexes(coll, { name: 'expire', key: { updateAt: 1 }, expireAfterSeconds: 24 * 2600 });
|
||||||
}
|
}
|
||||||
@@ -62,17 +62,14 @@ 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.find({ _id: { $gte: Time.getObjectID(moment().add(-5, 'minutes')) }, ...domainId ? { domainId } : {} }).count(),
|
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-5, 'minutes')) }, ...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, 'hour')) }, ...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, 'day')) }, ...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, 'week')) }, ...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, 'month')) }, ...domainId ? { domainId } : {} }),
|
||||||
RecordModel.coll.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'year')) }, ...domainId ? { domainId } : {} }).count(),
|
RecordModel.coll.countDocuments({ _id: { $gte: Time.getObjectID(moment().add(-1, 'year')) }, ...domainId ? { domainId } : {} }),
|
||||||
RecordModel.coll.find(domainId ? { domainId } : {}).count(),
|
domainId ? RecordModel.coll.countDocuments({ domainId }) : RecordModel.coll.estimatedDocumentCount(),
|
||||||
]);
|
]);
|
||||||
return {
|
return {
|
||||||
d5min, d1h, day, week, month, year, total,
|
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 [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.count(),
|
domain.coll.estimatedDocumentCount(),
|
||||||
user.coll.count(),
|
user.coll.estimatedDocumentCount(),
|
||||||
document.coll.count({ docType: document.TYPE_PROBLEM }),
|
document.coll.countDocuments({ docType: document.TYPE_PROBLEM }),
|
||||||
document.coll.count({ docType: document.TYPE_DISCUSSION }),
|
document.coll.countDocuments({ docType: document.TYPE_DISCUSSION }),
|
||||||
record.coll.count(),
|
record.coll.estimatedDocumentCount(),
|
||||||
]);
|
]);
|
||||||
const info: Record<string, any> = {
|
const info: Record<string, any> = {
|
||||||
mid: mid.toString(),
|
mid: mid.toString(),
|
||||||
|
|||||||
Reference in new issue
Block a user