Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import Chart from "../core.js";
|
||||
import { name, schema } from "./entities/active-users.js";
|
||||
const week = 1000 * 60 * 60 * 24 * 7;
|
||||
const month = 1000 * 60 * 60 * 24 * 30;
|
||||
const year = 1000 * 60 * 60 * 24 * 365;
|
||||
/**
|
||||
* アクティブユーザーに関するチャート
|
||||
*/ export default class ActiveUsersChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
read(user) {
|
||||
this.commit({
|
||||
read: [
|
||||
user.id
|
||||
],
|
||||
registeredWithinWeek: Date.now() - user.createdAt.getTime() < week ? [
|
||||
user.id
|
||||
] : [],
|
||||
registeredWithinMonth: Date.now() - user.createdAt.getTime() < month ? [
|
||||
user.id
|
||||
] : [],
|
||||
registeredWithinYear: Date.now() - user.createdAt.getTime() < year ? [
|
||||
user.id
|
||||
] : [],
|
||||
registeredOutsideWeek: Date.now() - user.createdAt.getTime() > week ? [
|
||||
user.id
|
||||
] : [],
|
||||
registeredOutsideMonth: Date.now() - user.createdAt.getTime() > month ? [
|
||||
user.id
|
||||
] : [],
|
||||
registeredOutsideYear: Date.now() - user.createdAt.getTime() > year ? [
|
||||
user.id
|
||||
] : []
|
||||
});
|
||||
}
|
||||
async write(user) {
|
||||
await this.commit({
|
||||
write: [
|
||||
user.id
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import Chart from "../core.js";
|
||||
import { name, schema } from "./entities/ap-request.js";
|
||||
/**
|
||||
* Chart about ActivityPub requests
|
||||
*/ export default class ApRequestChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async deliverSucc() {
|
||||
await this.commit({
|
||||
deliverSucceeded: 1
|
||||
});
|
||||
}
|
||||
async deliverFail() {
|
||||
await this.commit({
|
||||
deliverFailed: 1
|
||||
});
|
||||
}
|
||||
async inbox() {
|
||||
await this.commit({
|
||||
inboxReceived: 1
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Chart from "../core.js";
|
||||
import { name, schema } from "./entities/drive.js";
|
||||
/**
|
||||
* ドライブに関するチャート
|
||||
*/ export default class DriveChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async update(file, isAdditional) {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit(file.userHost === null ? {
|
||||
"local.incCount": isAdditional ? 1 : 0,
|
||||
"local.incSize": isAdditional ? fileSizeKb : 0,
|
||||
"local.decCount": isAdditional ? 0 : 1,
|
||||
"local.decSize": isAdditional ? 0 : fileSizeKb
|
||||
} : {
|
||||
"remote.incCount": isAdditional ? 1 : 0,
|
||||
"remote.incSize": isAdditional ? fileSizeKb : 0,
|
||||
"remote.decCount": isAdditional ? 0 : 1,
|
||||
"remote.decSize": isAdditional ? 0 : fileSizeKb
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "activeUsers";
|
||||
export const schema = {
|
||||
readWrite: {
|
||||
intersection: [
|
||||
"read",
|
||||
"write"
|
||||
],
|
||||
range: "small"
|
||||
},
|
||||
read: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
write: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
registeredWithinWeek: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
registeredWithinMonth: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
registeredWithinYear: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
registeredOutsideWeek: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
registeredOutsideMonth: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
registeredOutsideYear: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,8 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "apRequest";
|
||||
export const schema = {
|
||||
deliverFailed: {},
|
||||
deliverSucceeded: {},
|
||||
inboxReceived: {}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,13 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "drive";
|
||||
export const schema = {
|
||||
"local.incCount": {},
|
||||
"local.incSize": {},
|
||||
"local.decCount": {},
|
||||
"local.decSize": {},
|
||||
"remote.incCount": {},
|
||||
"remote.incSize": {},
|
||||
"remote.decCount": {},
|
||||
"remote.decSize": {}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,37 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "federation";
|
||||
export const schema = {
|
||||
deliveredInstances: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
inboxInstances: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
stalled: {
|
||||
uniqueIncrement: true,
|
||||
range: "small"
|
||||
},
|
||||
sub: {
|
||||
accumulate: true,
|
||||
range: "small"
|
||||
},
|
||||
pub: {
|
||||
accumulate: true,
|
||||
range: "small"
|
||||
},
|
||||
pubsub: {
|
||||
accumulate: true,
|
||||
range: "small"
|
||||
},
|
||||
subActive: {
|
||||
accumulate: true,
|
||||
range: "small"
|
||||
},
|
||||
pubActive: {
|
||||
accumulate: true,
|
||||
range: "small"
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,11 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "hashtag";
|
||||
export const schema = {
|
||||
"local.users": {
|
||||
uniqueIncrement: true
|
||||
},
|
||||
"remote.users": {
|
||||
uniqueIncrement: true
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema, true);
|
||||
@@ -0,0 +1,57 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "instance";
|
||||
export const schema = {
|
||||
"requests.failed": {
|
||||
range: "small"
|
||||
},
|
||||
"requests.succeeded": {
|
||||
range: "small"
|
||||
},
|
||||
"requests.received": {
|
||||
range: "small"
|
||||
},
|
||||
"notes.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"notes.inc": {},
|
||||
"notes.dec": {},
|
||||
"notes.diffs.normal": {},
|
||||
"notes.diffs.reply": {},
|
||||
"notes.diffs.renote": {},
|
||||
"notes.diffs.withFile": {},
|
||||
"users.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"users.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"users.dec": {
|
||||
range: "small"
|
||||
},
|
||||
"following.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"following.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"following.dec": {
|
||||
range: "small"
|
||||
},
|
||||
"followers.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"followers.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"followers.dec": {
|
||||
range: "small"
|
||||
},
|
||||
"drive.totalFiles": {
|
||||
accumulate: true
|
||||
},
|
||||
"drive.incFiles": {},
|
||||
"drive.decFiles": {},
|
||||
"drive.incUsage": {},
|
||||
"drive.decUsage": {}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema, true);
|
||||
@@ -0,0 +1,23 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "notes";
|
||||
export const schema = {
|
||||
"local.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"local.inc": {},
|
||||
"local.dec": {},
|
||||
"local.diffs.normal": {},
|
||||
"local.diffs.reply": {},
|
||||
"local.diffs.renote": {},
|
||||
"local.diffs.withFile": {},
|
||||
"remote.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"remote.inc": {},
|
||||
"remote.dec": {},
|
||||
"remote.diffs.normal": {},
|
||||
"remote.diffs.reply": {},
|
||||
"remote.diffs.renote": {},
|
||||
"remote.diffs.withFile": {}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,19 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "perUserDrive";
|
||||
export const schema = {
|
||||
totalCount: {
|
||||
accumulate: true
|
||||
},
|
||||
totalSize: {
|
||||
accumulate: true
|
||||
},
|
||||
incCount: {
|
||||
range: "small"
|
||||
},
|
||||
incSize: {},
|
||||
decCount: {
|
||||
range: "small"
|
||||
},
|
||||
decSize: {}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema, true);
|
||||
@@ -0,0 +1,41 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "perUserFollowing";
|
||||
export const schema = {
|
||||
"local.followings.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"local.followings.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"local.followings.dec": {
|
||||
range: "small"
|
||||
},
|
||||
"local.followers.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"local.followers.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"local.followers.dec": {
|
||||
range: "small"
|
||||
},
|
||||
"remote.followings.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"remote.followings.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"remote.followings.dec": {
|
||||
range: "small"
|
||||
},
|
||||
"remote.followers.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"remote.followers.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"remote.followers.dec": {
|
||||
range: "small"
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema, true);
|
||||
@@ -0,0 +1,26 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "perUserNotes";
|
||||
export const schema = {
|
||||
total: {
|
||||
accumulate: true
|
||||
},
|
||||
inc: {
|
||||
range: "small"
|
||||
},
|
||||
dec: {
|
||||
range: "small"
|
||||
},
|
||||
"diffs.normal": {
|
||||
range: "small"
|
||||
},
|
||||
"diffs.reply": {
|
||||
range: "small"
|
||||
},
|
||||
"diffs.renote": {
|
||||
range: "small"
|
||||
},
|
||||
"diffs.withFile": {
|
||||
range: "small"
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema, true);
|
||||
@@ -0,0 +1,11 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "perUserReaction";
|
||||
export const schema = {
|
||||
"local.count": {
|
||||
range: "small"
|
||||
},
|
||||
"remote.count": {
|
||||
range: "small"
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema, true);
|
||||
@@ -0,0 +1,10 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "testGrouped";
|
||||
export const schema = {
|
||||
"foo.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"foo.inc": {},
|
||||
"foo.dec": {}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema, true);
|
||||
@@ -0,0 +1,17 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "testIntersection";
|
||||
export const schema = {
|
||||
a: {
|
||||
uniqueIncrement: true
|
||||
},
|
||||
b: {
|
||||
uniqueIncrement: true
|
||||
},
|
||||
aAndB: {
|
||||
intersection: [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,8 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "testUnique";
|
||||
export const schema = {
|
||||
foo: {
|
||||
uniqueIncrement: true
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,10 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "test";
|
||||
export const schema = {
|
||||
"foo.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"foo.inc": {},
|
||||
"foo.dec": {}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,23 @@
|
||||
import Chart from "../../core.js";
|
||||
export const name = "users";
|
||||
export const schema = {
|
||||
"local.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"local.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"local.dec": {
|
||||
range: "small"
|
||||
},
|
||||
"remote.total": {
|
||||
accumulate: true
|
||||
},
|
||||
"remote.inc": {
|
||||
range: "small"
|
||||
},
|
||||
"remote.dec": {
|
||||
range: "small"
|
||||
}
|
||||
};
|
||||
export const entity = Chart.schemaToEntity(name, schema);
|
||||
@@ -0,0 +1,67 @@
|
||||
import Chart from "../core.js";
|
||||
import { Followings, Instances } from "../../../models/index.js";
|
||||
import { name, schema } from "./entities/federation.js";
|
||||
import { fetchMeta } from "../../../misc/fetch-meta.js";
|
||||
/**
|
||||
* フェデレーションに関するチャート
|
||||
*/ export default class FederationChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
const meta = await fetchMeta();
|
||||
const suspendedInstancesQuery = Instances.createQueryBuilder("instance").select("instance.host").where("instance.isSuspended = true");
|
||||
const pubsubSubQuery = Followings.createQueryBuilder("f").select("f.followerHost").where("f.followerHost IS NOT NULL");
|
||||
const subInstancesQuery = Followings.createQueryBuilder("f").select("f.followeeHost").where("f.followeeHost IS NOT NULL");
|
||||
const pubInstancesQuery = Followings.createQueryBuilder("f").select("f.followerHost").where("f.followerHost IS NOT NULL");
|
||||
const [sub, pub, pubsub, subActive, pubActive] = await Promise.all([
|
||||
Followings.createQueryBuilder("following").select("COUNT(DISTINCT following.followeeHost)").where("following.followeeHost IS NOT NULL").andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followeeHost NOT IN (:...blocked)", {
|
||||
blocked: meta.blockedHosts
|
||||
}).andWhere(`following.followeeHost NOT IN (${suspendedInstancesQuery.getQuery()})`).getRawOne().then((x)=>parseInt(x.count, 10)),
|
||||
Followings.createQueryBuilder("following").select("COUNT(DISTINCT following.followerHost)").where("following.followerHost IS NOT NULL").andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followerHost NOT IN (:...blocked)", {
|
||||
blocked: meta.blockedHosts
|
||||
}).andWhere(`following.followerHost NOT IN (${suspendedInstancesQuery.getQuery()})`).getRawOne().then((x)=>parseInt(x.count, 10)),
|
||||
Followings.createQueryBuilder("following").select("COUNT(DISTINCT following.followeeHost)").where("following.followeeHost IS NOT NULL").andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followeeHost NOT IN (:...blocked)", {
|
||||
blocked: meta.blockedHosts
|
||||
}).andWhere(`following.followeeHost NOT IN (${suspendedInstancesQuery.getQuery()})`).andWhere(`following.followeeHost IN (${pubsubSubQuery.getQuery()})`).setParameters(pubsubSubQuery.getParameters()).getRawOne().then((x)=>parseInt(x.count, 10)),
|
||||
Instances.createQueryBuilder("instance").select("COUNT(instance.id)").where(`instance.host IN (${subInstancesQuery.getQuery()})`).andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT IN (:...blocked)", {
|
||||
blocked: meta.blockedHosts
|
||||
}).andWhere("instance.isSuspended = false").andWhere("instance.lastCommunicatedAt > :gt", {
|
||||
gt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30)
|
||||
}).getRawOne().then((x)=>parseInt(x.count, 10)),
|
||||
Instances.createQueryBuilder("instance").select("COUNT(instance.id)").where(`instance.host IN (${pubInstancesQuery.getQuery()})`).andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT IN (:...blocked)", {
|
||||
blocked: meta.blockedHosts
|
||||
}).andWhere("instance.isSuspended = false").andWhere("instance.lastCommunicatedAt > :gt", {
|
||||
gt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30)
|
||||
}).getRawOne().then((x)=>parseInt(x.count, 10))
|
||||
]);
|
||||
return {
|
||||
sub: sub,
|
||||
pub: pub,
|
||||
pubsub: pubsub,
|
||||
subActive: subActive,
|
||||
pubActive: pubActive
|
||||
};
|
||||
}
|
||||
async deliverd(host, succeeded) {
|
||||
await this.commit(succeeded ? {
|
||||
deliveredInstances: [
|
||||
host
|
||||
]
|
||||
} : {
|
||||
stalled: [
|
||||
host
|
||||
]
|
||||
});
|
||||
}
|
||||
async inbox(host) {
|
||||
await this.commit({
|
||||
inboxInstances: [
|
||||
host
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import Chart from "../core.js";
|
||||
import { Users } from "../../../models/index.js";
|
||||
import { name, schema } from "./entities/hashtag.js";
|
||||
/**
|
||||
* ハッシュタグに関するチャート
|
||||
*/ export default class HashtagChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema, true);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async update(hashtag, user) {
|
||||
await this.commit({
|
||||
"local.users": Users.isLocalUser(user) ? [
|
||||
user.id
|
||||
] : [],
|
||||
"remote.users": Users.isLocalUser(user) ? [] : [
|
||||
user.id
|
||||
]
|
||||
}, hashtag);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import Chart from "../core.js";
|
||||
import { DriveFiles, Followings, Users, Notes } from "../../../models/index.js";
|
||||
import { toPuny } from "../../../misc/convert-host.js";
|
||||
import { name, schema } from "./entities/instance.js";
|
||||
/**
|
||||
* インスタンスごとのチャート
|
||||
*/ export default class InstanceChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema, true);
|
||||
}
|
||||
async tickMajor(group) {
|
||||
const [notesCount, usersCount, followingCount, followersCount, driveFiles] = await Promise.all([
|
||||
Notes.countBy({
|
||||
userHost: group
|
||||
}),
|
||||
Users.countBy({
|
||||
host: group
|
||||
}),
|
||||
Followings.countBy({
|
||||
followerHost: group
|
||||
}),
|
||||
Followings.countBy({
|
||||
followeeHost: group
|
||||
}),
|
||||
DriveFiles.countBy({
|
||||
userHost: group
|
||||
})
|
||||
]);
|
||||
return {
|
||||
"notes.total": notesCount,
|
||||
"users.total": usersCount,
|
||||
"following.total": followingCount,
|
||||
"followers.total": followersCount,
|
||||
"drive.totalFiles": driveFiles
|
||||
};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async requestReceived(host) {
|
||||
await this.commit({
|
||||
"requests.received": 1
|
||||
}, toPuny(host));
|
||||
}
|
||||
async requestSent(host, isSucceeded) {
|
||||
await this.commit({
|
||||
"requests.succeeded": isSucceeded ? 1 : 0,
|
||||
"requests.failed": isSucceeded ? 0 : 1
|
||||
}, toPuny(host));
|
||||
}
|
||||
async newUser(host) {
|
||||
await this.commit({
|
||||
"users.total": 1,
|
||||
"users.inc": 1
|
||||
}, toPuny(host));
|
||||
}
|
||||
async updateNote(host, note, isAdditional) {
|
||||
await this.commit({
|
||||
"notes.total": isAdditional ? 1 : -1,
|
||||
"notes.inc": isAdditional ? 1 : 0,
|
||||
"notes.dec": isAdditional ? 0 : 1,
|
||||
"notes.diffs.normal": note.replyId == null && note.renoteId == null ? isAdditional ? 1 : -1 : 0,
|
||||
"notes.diffs.renote": note.renoteId != null ? isAdditional ? 1 : -1 : 0,
|
||||
"notes.diffs.reply": note.replyId != null ? isAdditional ? 1 : -1 : 0,
|
||||
"notes.diffs.withFile": note.fileIds.length > 0 ? isAdditional ? 1 : -1 : 0
|
||||
}, toPuny(host));
|
||||
}
|
||||
async updateFollowing(host, isAdditional) {
|
||||
await this.commit({
|
||||
"following.total": isAdditional ? 1 : -1,
|
||||
"following.inc": isAdditional ? 1 : 0,
|
||||
"following.dec": isAdditional ? 0 : 1
|
||||
}, toPuny(host));
|
||||
}
|
||||
async updateFollowers(host, isAdditional) {
|
||||
await this.commit({
|
||||
"followers.total": isAdditional ? 1 : -1,
|
||||
"followers.inc": isAdditional ? 1 : 0,
|
||||
"followers.dec": isAdditional ? 0 : 1
|
||||
}, toPuny(host));
|
||||
}
|
||||
async updateDrive(file, isAdditional) {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit({
|
||||
"drive.totalFiles": isAdditional ? 1 : -1,
|
||||
"drive.incFiles": isAdditional ? 1 : 0,
|
||||
"drive.incUsage": isAdditional ? fileSizeKb : 0,
|
||||
"drive.decFiles": isAdditional ? 1 : 0,
|
||||
"drive.decUsage": isAdditional ? fileSizeKb : 0
|
||||
}, file.userHost);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import Chart from "../core.js";
|
||||
import { Notes } from "../../../models/index.js";
|
||||
import { Not, IsNull } from "typeorm";
|
||||
import { name, schema } from "./entities/notes.js";
|
||||
/**
|
||||
* ノートに関するチャート
|
||||
*/ export default class NotesChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
const [localCount, remoteCount] = await Promise.all([
|
||||
Notes.countBy({
|
||||
userHost: IsNull()
|
||||
}),
|
||||
Notes.countBy({
|
||||
userHost: Not(IsNull())
|
||||
})
|
||||
]);
|
||||
return {
|
||||
"local.total": localCount,
|
||||
"remote.total": remoteCount
|
||||
};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async update(note, isAdditional) {
|
||||
const prefix = note.userHost === null ? "local" : "remote";
|
||||
await this.commit({
|
||||
[`${prefix}.total`]: isAdditional ? 1 : -1,
|
||||
[`${prefix}.inc`]: isAdditional ? 1 : 0,
|
||||
[`${prefix}.dec`]: isAdditional ? 0 : 1,
|
||||
[`${prefix}.diffs.normal`]: note.replyId == null && note.renoteId == null ? isAdditional ? 1 : -1 : 0,
|
||||
[`${prefix}.diffs.renote`]: note.renoteId != null ? isAdditional ? 1 : -1 : 0,
|
||||
[`${prefix}.diffs.reply`]: note.replyId != null ? isAdditional ? 1 : -1 : 0,
|
||||
[`${prefix}.diffs.withFile`]: note.fileIds.length > 0 ? isAdditional ? 1 : -1 : 0
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import Chart from "../core.js";
|
||||
import { DriveFiles } from "../../../models/index.js";
|
||||
import { name, schema } from "./entities/per-user-drive.js";
|
||||
/**
|
||||
* ユーザーごとのドライブに関するチャート
|
||||
*/ export default class PerUserDriveChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema, true);
|
||||
}
|
||||
async tickMajor(group) {
|
||||
const [count, size] = await Promise.all([
|
||||
DriveFiles.countBy({
|
||||
userId: group
|
||||
}),
|
||||
DriveFiles.calcDriveUsageOf(group)
|
||||
]);
|
||||
return {
|
||||
totalCount: count,
|
||||
totalSize: size
|
||||
};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async update(file, isAdditional) {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit({
|
||||
totalCount: isAdditional ? 1 : -1,
|
||||
totalSize: isAdditional ? fileSizeKb : -fileSizeKb,
|
||||
incCount: isAdditional ? 1 : 0,
|
||||
incSize: isAdditional ? fileSizeKb : 0,
|
||||
decCount: isAdditional ? 0 : 1,
|
||||
decSize: isAdditional ? 0 : fileSizeKb
|
||||
}, file.userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import Chart from "../core.js";
|
||||
import { Followings, Users } from "../../../models/index.js";
|
||||
import { Not, IsNull } from "typeorm";
|
||||
import { name, schema } from "./entities/per-user-following.js";
|
||||
/**
|
||||
* ユーザーごとのフォローに関するチャート
|
||||
*/ export default class PerUserFollowingChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema, true);
|
||||
}
|
||||
async tickMajor(group) {
|
||||
const [localFollowingsCount, localFollowersCount, remoteFollowingsCount, remoteFollowersCount] = await Promise.all([
|
||||
Followings.countBy({
|
||||
followerId: group,
|
||||
followeeHost: IsNull()
|
||||
}),
|
||||
Followings.countBy({
|
||||
followeeId: group,
|
||||
followerHost: IsNull()
|
||||
}),
|
||||
Followings.countBy({
|
||||
followerId: group,
|
||||
followeeHost: Not(IsNull())
|
||||
}),
|
||||
Followings.countBy({
|
||||
followeeId: group,
|
||||
followerHost: Not(IsNull())
|
||||
})
|
||||
]);
|
||||
return {
|
||||
"local.followings.total": localFollowingsCount,
|
||||
"local.followers.total": localFollowersCount,
|
||||
"remote.followings.total": remoteFollowingsCount,
|
||||
"remote.followers.total": remoteFollowersCount
|
||||
};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async update(follower, followee, isFollow) {
|
||||
const prefixFollower = Users.isLocalUser(follower) ? "local" : "remote";
|
||||
const prefixFollowee = Users.isLocalUser(followee) ? "local" : "remote";
|
||||
this.commit({
|
||||
[`${prefixFollower}.followings.total`]: isFollow ? 1 : -1,
|
||||
[`${prefixFollower}.followings.inc`]: isFollow ? 1 : 0,
|
||||
[`${prefixFollower}.followings.dec`]: isFollow ? 0 : 1
|
||||
}, follower.id);
|
||||
this.commit({
|
||||
[`${prefixFollowee}.followers.total`]: isFollow ? 1 : -1,
|
||||
[`${prefixFollowee}.followers.inc`]: isFollow ? 1 : 0,
|
||||
[`${prefixFollowee}.followers.dec`]: isFollow ? 0 : 1
|
||||
}, followee.id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import Chart from "../core.js";
|
||||
import { Notes } from "../../../models/index.js";
|
||||
import { name, schema } from "./entities/per-user-notes.js";
|
||||
/**
|
||||
* ユーザーごとのノートに関するチャート
|
||||
*/ export default class PerUserNotesChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema, true);
|
||||
}
|
||||
async tickMajor(group) {
|
||||
const [count] = await Promise.all([
|
||||
Notes.countBy({
|
||||
userId: group
|
||||
})
|
||||
]);
|
||||
return {
|
||||
total: count
|
||||
};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async update(user, note, isAdditional) {
|
||||
await this.commit({
|
||||
total: isAdditional ? 1 : -1,
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
"diffs.normal": note.replyId == null && note.renoteId == null ? isAdditional ? 1 : -1 : 0,
|
||||
"diffs.renote": note.renoteId != null ? isAdditional ? 1 : -1 : 0,
|
||||
"diffs.reply": note.replyId != null ? isAdditional ? 1 : -1 : 0,
|
||||
"diffs.withFile": note.fileIds.length > 0 ? isAdditional ? 1 : -1 : 0
|
||||
}, user.id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import Chart from "../core.js";
|
||||
import { Users } from "../../../models/index.js";
|
||||
import { name, schema } from "./entities/per-user-reactions.js";
|
||||
/**
|
||||
* ユーザーごとのリアクションに関するチャート
|
||||
*/ export default class PerUserReactionsChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema, true);
|
||||
}
|
||||
async tickMajor(group) {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async update(user, note) {
|
||||
const prefix = Users.isLocalUser(user) ? "local" : "remote";
|
||||
this.commit({
|
||||
[`${prefix}.count`]: 1
|
||||
}, note.userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import Chart from "../core.js";
|
||||
import { name, schema } from "./entities/test-grouped.js";
|
||||
/**
|
||||
* For testing
|
||||
*/ export default class TestGroupedChart extends Chart {
|
||||
total = {};
|
||||
constructor(){
|
||||
super(name, schema, true);
|
||||
}
|
||||
async tickMajor(group) {
|
||||
return {
|
||||
"foo.total": this.total[group]
|
||||
};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async increment(group) {
|
||||
if (this.total[group] == null) this.total[group] = 0;
|
||||
this.total[group]++;
|
||||
await this.commit({
|
||||
"foo.total": 1,
|
||||
"foo.inc": 1
|
||||
}, group);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Chart from "../core.js";
|
||||
import { name, schema } from "./entities/test-intersection.js";
|
||||
/**
|
||||
* For testing
|
||||
*/ export default class TestIntersectionChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async addA(key) {
|
||||
await this.commit({
|
||||
a: [
|
||||
key
|
||||
]
|
||||
});
|
||||
}
|
||||
async addB(key) {
|
||||
await this.commit({
|
||||
b: [
|
||||
key
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import Chart from "../core.js";
|
||||
import { name, schema } from "./entities/test-unique.js";
|
||||
/**
|
||||
* For testing
|
||||
*/ export default class TestUniqueChart extends Chart {
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async uniqueIncrement(key) {
|
||||
await this.commit({
|
||||
foo: [
|
||||
key
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import Chart from "../core.js";
|
||||
import { name, schema } from "./entities/test.js";
|
||||
/**
|
||||
* For testing
|
||||
*/ export default class TestChart extends Chart {
|
||||
total = 0;
|
||||
constructor(){
|
||||
super(name, schema);
|
||||
}
|
||||
async tickMajor() {
|
||||
return {
|
||||
"foo.total": this.total
|
||||
};
|
||||
}
|
||||
async tickMinor() {
|
||||
return {};
|
||||
}
|
||||
async increment() {
|
||||
this.total++;
|
||||
await this.commit({
|
||||
"foo.total": 1,
|
||||
"foo.inc": 1
|
||||
});
|
||||
}
|
||||
async decrement() {
|
||||
this.total--;
|
||||
await this.commit({
|
||||
"foo.total": -1,
|
||||
"foo.dec": 1
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user