Files
FrozenFriendsYume/packages/backend/built/services/chart/charts/users.js
T
2026-07-26 18:25:37 +09:00

37 lines
1.0 KiB
JavaScript

import Chart from "../core.js";
import { Users } from "../../../models/index.js";
import { Not, IsNull } from "typeorm";
import { name, schema } from "./entities/users.js";
/**
* ユーザー数に関するチャート
*/ export default class UsersChart extends Chart {
constructor(){
super(name, schema);
}
async tickMajor() {
const [localCount, remoteCount] = await Promise.all([
Users.countBy({
host: IsNull()
}),
Users.countBy({
host: Not(IsNull())
})
]);
return {
"local.total": localCount,
"remote.total": remoteCount
};
}
async tickMinor() {
return {};
}
async update(user, isAdditional) {
const prefix = Users.isLocalUser(user) ? "local" : "remote";
await this.commit({
[`${prefix}.total`]: isAdditional ? 1 : -1,
[`${prefix}.inc`]: isAdditional ? 1 : 0,
[`${prefix}.dec`]: isAdditional ? 0 : 1
});
}
}