mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-06 16:53:58 +09:00
refactor: Use ESM (#8358)
* wip * wip * fix * clean up * Update tsconfig.json * Update activitypub.ts * wip
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { Users } from '@/models/index';
|
||||
import { name, schema } from './entities/active-users';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { name, schema } from './entities/active-users.js';
|
||||
|
||||
const week = 1000 * 60 * 60 * 24 * 7;
|
||||
const month = 1000 * 60 * 60 * 24 * 30;
|
||||
@ -17,17 +16,14 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async read(user: { id: User['id'], host: null, createdAt: User['createdAt'] }): Promise<void> {
|
||||
await this.commit({
|
||||
'read': [user.id],
|
||||
@ -40,7 +36,6 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async write(user: { id: User['id'], host: null, createdAt: User['createdAt'] }): Promise<void> {
|
||||
await this.commit({
|
||||
'write': [user.id],
|
||||
|
@ -1,6 +1,5 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { name, schema } from './entities/ap-request';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { name, schema } from './entities/ap-request.js';
|
||||
|
||||
/**
|
||||
* Chart about ActivityPub requests
|
||||
@ -11,31 +10,26 @@ export default class ApRequestChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async deliverSucc(): Promise<void> {
|
||||
await this.commit({
|
||||
'deliverSucceeded': 1,
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async deliverFail(): Promise<void> {
|
||||
await this.commit({
|
||||
'deliverFailed': 1,
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async inbox(): Promise<void> {
|
||||
await this.commit({
|
||||
'inboxReceived': 1,
|
||||
|
@ -1,9 +1,8 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { DriveFiles } from '@/models/index';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { DriveFiles } from '@/models/index.js';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { DriveFile } from '@/models/entities/drive-file';
|
||||
import { name, schema } from './entities/drive';
|
||||
import { DriveFile } from '@/models/entities/drive-file.js';
|
||||
import { name, schema } from './entities/drive.js';
|
||||
|
||||
/**
|
||||
* ドライブに関するチャート
|
||||
@ -14,17 +13,14 @@ export default class DriveChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(file: DriveFile, isAdditional: boolean): Promise<void> {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit(file.userHost === null ? {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'activeUsers';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'apRequest';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'drive';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'federation';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'hashtag';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'instance';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'notes';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'perUserDrive';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'perUserFollowing';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'perUserNotes';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'perUserReaction';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'testGrouped';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'testIntersection';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'testUnique';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'test';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Chart from '../../core';
|
||||
import Chart from '../../core.js';
|
||||
|
||||
export const name = 'users';
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { Followings } from '@/models/index';
|
||||
import { name, schema } from './entities/federation';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { Followings } from '@/models/index.js';
|
||||
import { name, schema } from './entities/federation.js';
|
||||
|
||||
/**
|
||||
* フェデレーションに関するチャート
|
||||
@ -12,13 +11,11 @@ export default class FederationChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
const pubsubSubQuery = Followings.createQueryBuilder('f')
|
||||
.select('f.followerHost')
|
||||
@ -51,7 +48,6 @@ export default class FederationChart extends Chart<typeof schema> {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async deliverd(host: string, succeeded: boolean): Promise<void> {
|
||||
await this.commit(succeeded ? {
|
||||
'deliveredInstances': [host],
|
||||
@ -60,7 +56,6 @@ export default class FederationChart extends Chart<typeof schema> {
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async inbox(host: string): Promise<void> {
|
||||
await this.commit({
|
||||
'inboxInstances': [host],
|
||||
|
@ -1,8 +1,7 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { Users } from '@/models/index';
|
||||
import { name, schema } from './entities/hashtag';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { name, schema } from './entities/hashtag.js';
|
||||
|
||||
/**
|
||||
* ハッシュタグに関するチャート
|
||||
@ -13,17 +12,14 @@ export default class HashtagChart extends Chart<typeof schema> {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(hashtag: string, user: { id: User['id'], host: User['host'] }): Promise<void> {
|
||||
await this.commit({
|
||||
'local.users': Users.isLocalUser(user) ? [user.id] : [],
|
||||
|
@ -1,10 +1,9 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { DriveFiles, Followings, Users, Notes } from '@/models/index';
|
||||
import { DriveFile } from '@/models/entities/drive-file';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { toPuny } from '@/misc/convert-host';
|
||||
import { name, schema } from './entities/instance';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { DriveFiles, Followings, Users, Notes } from '@/models/index.js';
|
||||
import { DriveFile } from '@/models/entities/drive-file.js';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { toPuny } from '@/misc/convert-host.js';
|
||||
import { name, schema } from './entities/instance.js';
|
||||
|
||||
/**
|
||||
* インスタンスごとのチャート
|
||||
@ -15,7 +14,6 @@ export default class InstanceChart extends Chart<typeof schema> {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(group: string): Promise<Partial<KVs<typeof schema>>> {
|
||||
const [
|
||||
notesCount,
|
||||
@ -42,19 +40,16 @@ export default class InstanceChart extends Chart<typeof schema> {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async requestReceived(host: string): Promise<void> {
|
||||
await this.commit({
|
||||
'requests.received': 1,
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async requestSent(host: string, isSucceeded: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'requests.succeeded': isSucceeded ? 1 : 0,
|
||||
@ -62,7 +57,6 @@ export default class InstanceChart extends Chart<typeof schema> {
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async newUser(host: string): Promise<void> {
|
||||
await this.commit({
|
||||
'users.total': 1,
|
||||
@ -70,7 +64,6 @@ export default class InstanceChart extends Chart<typeof schema> {
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateNote(host: string, note: Note, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'notes.total': isAdditional ? 1 : -1,
|
||||
@ -83,7 +76,6 @@ export default class InstanceChart extends Chart<typeof schema> {
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateFollowing(host: string, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'following.total': isAdditional ? 1 : -1,
|
||||
@ -92,7 +84,6 @@ export default class InstanceChart extends Chart<typeof schema> {
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateFollowers(host: string, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'followers.total': isAdditional ? 1 : -1,
|
||||
@ -101,7 +92,6 @@ export default class InstanceChart extends Chart<typeof schema> {
|
||||
}, toPuny(host));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateDrive(file: DriveFile, isAdditional: boolean): Promise<void> {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit({
|
||||
|
@ -1,9 +1,8 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { Notes } from '@/models/index';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { Notes } from '@/models/index.js';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { name, schema } from './entities/notes';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { name, schema } from './entities/notes.js';
|
||||
|
||||
/**
|
||||
* ノートに関するチャート
|
||||
@ -14,7 +13,6 @@ export default class NotesChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
const [localCount, remoteCount] = await Promise.all([
|
||||
Notes.count({ userHost: null }),
|
||||
@ -27,12 +25,10 @@ export default class NotesChart extends Chart<typeof schema> {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(note: Note, isAdditional: boolean): Promise<void> {
|
||||
const prefix = note.userHost === null ? 'local' : 'remote';
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { DriveFiles } from '@/models/index';
|
||||
import { DriveFile } from '@/models/entities/drive-file';
|
||||
import { name, schema } from './entities/per-user-drive';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { DriveFiles } from '@/models/index.js';
|
||||
import { DriveFile } from '@/models/entities/drive-file.js';
|
||||
import { name, schema } from './entities/per-user-drive.js';
|
||||
|
||||
/**
|
||||
* ユーザーごとのドライブに関するチャート
|
||||
@ -13,7 +12,6 @@ export default class PerUserDriveChart extends Chart<typeof schema> {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(group: string): Promise<Partial<KVs<typeof schema>>> {
|
||||
const [count, size] = await Promise.all([
|
||||
DriveFiles.count({ userId: group }),
|
||||
@ -26,12 +24,10 @@ export default class PerUserDriveChart extends Chart<typeof schema> {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(file: DriveFile, isAdditional: boolean): Promise<void> {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit({
|
||||
|
@ -1,9 +1,8 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { Followings, Users } from '@/models/index';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { Followings, Users } from '@/models/index.js';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { name, schema } from './entities/per-user-following';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { name, schema } from './entities/per-user-following.js';
|
||||
|
||||
/**
|
||||
* ユーザーごとのフォローに関するチャート
|
||||
@ -14,7 +13,6 @@ export default class PerUserFollowingChart extends Chart<typeof schema> {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(group: string): Promise<Partial<KVs<typeof schema>>> {
|
||||
const [
|
||||
localFollowingsCount,
|
||||
@ -36,12 +34,10 @@ export default class PerUserFollowingChart extends Chart<typeof schema> {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }, isFollow: boolean): Promise<void> {
|
||||
const prefixFollower = Users.isLocalUser(follower) ? 'local' : 'remote';
|
||||
const prefixFollowee = Users.isLocalUser(followee) ? 'local' : 'remote';
|
||||
|
@ -1,9 +1,8 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { Notes } from '@/models/index';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { name, schema } from './entities/per-user-notes';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { Notes } from '@/models/index.js';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { name, schema } from './entities/per-user-notes.js';
|
||||
|
||||
/**
|
||||
* ユーザーごとのノートに関するチャート
|
||||
@ -14,7 +13,6 @@ export default class PerUserNotesChart extends Chart<typeof schema> {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(group: string): Promise<Partial<KVs<typeof schema>>> {
|
||||
const [count] = await Promise.all([
|
||||
Notes.count({ userId: group }),
|
||||
@ -25,12 +23,10 @@ export default class PerUserNotesChart extends Chart<typeof schema> {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: { id: User['id'] }, note: Note, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'total': isAdditional ? 1 : -1,
|
||||
|
@ -1,9 +1,8 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { Note } from '@/models/entities/note';
|
||||
import { Users } from '@/models/index';
|
||||
import { name, schema } from './entities/per-user-reactions';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { name, schema } from './entities/per-user-reactions.js';
|
||||
|
||||
/**
|
||||
* ユーザーごとのリアクションに関するチャート
|
||||
@ -14,17 +13,14 @@ export default class PerUserReactionsChart extends Chart<typeof schema> {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(group: string): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: { id: User['id'], host: User['host'] }, note: Note): Promise<void> {
|
||||
const prefix = Users.isLocalUser(user) ? 'local' : 'remote';
|
||||
this.commit({
|
||||
|
@ -1,6 +1,5 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { name, schema } from './entities/test-grouped';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { name, schema } from './entities/test-grouped.js';
|
||||
|
||||
/**
|
||||
* For testing
|
||||
@ -13,19 +12,16 @@ export default class TestGroupedChart extends Chart<typeof schema> {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(group: string): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {
|
||||
'foo.total': this.total[group],
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment(group: string): Promise<void> {
|
||||
if (this.total[group] == null) this.total[group] = 0;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { name, schema } from './entities/test-intersection';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { name, schema } from './entities/test-intersection.js';
|
||||
|
||||
/**
|
||||
* For testing
|
||||
@ -11,24 +10,20 @@ export default class TestIntersectionChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async addA(key: string): Promise<void> {
|
||||
await this.commit({
|
||||
a: [key],
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async addB(key: string): Promise<void> {
|
||||
await this.commit({
|
||||
b: [key],
|
||||
|
@ -1,6 +1,5 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { name, schema } from './entities/test-unique';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { name, schema } from './entities/test-unique.js';
|
||||
|
||||
/**
|
||||
* For testing
|
||||
@ -11,17 +10,14 @@ export default class TestUniqueChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async uniqueIncrement(key: string): Promise<void> {
|
||||
await this.commit({
|
||||
foo: [key],
|
||||
|
@ -1,6 +1,5 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { name, schema } from './entities/test';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { name, schema } from './entities/test.js';
|
||||
|
||||
/**
|
||||
* For testing
|
||||
@ -13,19 +12,16 @@ export default class TestChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {
|
||||
'foo.total': this.total,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment(): Promise<void> {
|
||||
this.total++;
|
||||
|
||||
@ -35,7 +31,6 @@ export default class TestChart extends Chart<typeof schema> {
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async decrement(): Promise<void> {
|
||||
this.total--;
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
import autobind from 'autobind-decorator';
|
||||
import Chart, { KVs } from '../core';
|
||||
import { Users } from '@/models/index';
|
||||
import Chart, { KVs } from '../core.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { User } from '@/models/entities/user';
|
||||
import { name, schema } from './entities/users';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { name, schema } from './entities/users.js';
|
||||
|
||||
/**
|
||||
* ユーザー数に関するチャート
|
||||
@ -14,7 +13,6 @@ export default class UsersChart extends Chart<typeof schema> {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
const [localCount, remoteCount] = await Promise.all([
|
||||
Users.count({ host: null }),
|
||||
@ -27,12 +25,10 @@ export default class UsersChart extends Chart<typeof schema> {
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: { id: User['id'], host: User['host'] }, isAdditional: boolean): Promise<void> {
|
||||
const prefix = Users.isLocalUser(user) ? 'local' : 'remote';
|
||||
|
||||
|
@ -5,11 +5,10 @@
|
||||
*/
|
||||
|
||||
import * as nestedProperty from 'nested-property';
|
||||
import autobind from 'autobind-decorator';
|
||||
import Logger from '../logger';
|
||||
import Logger from '../logger.js';
|
||||
import { EntitySchema, getRepository, Repository, LessThan, Between } from 'typeorm';
|
||||
import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/prelude/time';
|
||||
import { getChartInsertLock } from '@/misc/app-lock';
|
||||
import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/prelude/time.js';
|
||||
import { getChartInsertLock } from '@/misc/app-lock.js';
|
||||
|
||||
const logger = new Logger('chart', 'white', process.env.NODE_ENV !== 'test');
|
||||
|
||||
@ -142,7 +141,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
*/
|
||||
protected abstract tickMinor(group: string | null): Promise<Partial<KVs<T>>>;
|
||||
|
||||
@autobind
|
||||
private static convertSchemaToColumnDefinitions(schema: Schema): Record<string, { type: string; array?: boolean; default?: any; }> {
|
||||
const columns = {} as Record<string, { type: string; array?: boolean; default?: any; }>;
|
||||
for (const [k, v] of Object.entries(schema)) {
|
||||
@ -168,12 +166,10 @@ export default abstract class Chart<T extends Schema> {
|
||||
return columns;
|
||||
}
|
||||
|
||||
@autobind
|
||||
private static dateToTimestamp(x: Date): number {
|
||||
return Math.floor(x.getTime() / 1000);
|
||||
}
|
||||
|
||||
@autobind
|
||||
private static parseDate(date: Date): [number, number, number, number, number, number, number] {
|
||||
const y = date.getUTCFullYear();
|
||||
const m = date.getUTCMonth();
|
||||
@ -186,12 +182,10 @@ export default abstract class Chart<T extends Schema> {
|
||||
return [y, m, d, h, _m, _s, _ms];
|
||||
}
|
||||
|
||||
@autobind
|
||||
private static getCurrentDate() {
|
||||
return Chart.parseDate(new Date());
|
||||
}
|
||||
|
||||
@autobind
|
||||
public static schemaToEntity(name: string, schema: Schema, grouped = false): {
|
||||
hour: EntitySchema,
|
||||
day: EntitySchema,
|
||||
@ -251,7 +245,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
this.repositoryForDay = getRepository<{ id: number; group?: string | null; date: number; }>(day);
|
||||
}
|
||||
|
||||
@autobind
|
||||
private convertRawRecord(x: RawRecord<T>): KVs<T> {
|
||||
const kvs = {} as Record<string, number>;
|
||||
for (const k of Object.keys(x).filter((k) => k.startsWith(columnPrefix)) as (keyof Columns<T>)[]) {
|
||||
@ -260,7 +253,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
return kvs as KVs<T>;
|
||||
}
|
||||
|
||||
@autobind
|
||||
private getNewLog(latest: KVs<T> | null): KVs<T> {
|
||||
const log = {} as Record<keyof T, number>;
|
||||
for (const [k, v] of Object.entries(this.schema) as ([keyof typeof this['schema'], this['schema'][string]])[]) {
|
||||
@ -273,7 +265,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
return log as KVs<T>;
|
||||
}
|
||||
|
||||
@autobind
|
||||
private getLatestLog(group: string | null, span: 'hour' | 'day'): Promise<RawRecord<T> | null> {
|
||||
const repository =
|
||||
span === 'hour' ? this.repositoryForHour :
|
||||
@ -292,7 +283,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
/**
|
||||
* 現在(=今のHour or Day)のログをデータベースから探して、あればそれを返し、なければ作成して返します。
|
||||
*/
|
||||
@autobind
|
||||
private async claimCurrentLog(group: string | null, span: 'hour' | 'day'): Promise<RawRecord<T>> {
|
||||
const [y, m, d, h] = Chart.getCurrentDate();
|
||||
|
||||
@ -376,7 +366,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected commit(diff: Commit<T>, group: string | null = null): void {
|
||||
for (const [k, v] of Object.entries(diff)) {
|
||||
if (v == null || v === 0 || (Array.isArray(v) && v.length === 0)) delete diff[k];
|
||||
@ -386,7 +375,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async save(): Promise<void> {
|
||||
if (this.buffer.length === 0) {
|
||||
logger.info(`${this.name}: Write skipped`);
|
||||
@ -505,7 +493,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
update(logHour, logDay))));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async tick(major: boolean, group: string | null = null): Promise<void> {
|
||||
const data = major ? await this.tickMajor(group) : await this.tickMinor(group);
|
||||
|
||||
@ -541,12 +528,10 @@ export default abstract class Chart<T extends Schema> {
|
||||
update(logHour, logDay));
|
||||
}
|
||||
|
||||
@autobind
|
||||
public resync(group: string | null = null): Promise<void> {
|
||||
return this.tick(true, group);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async clean(): Promise<void> {
|
||||
const current = dateUTC(Chart.getCurrentDate());
|
||||
|
||||
@ -582,7 +567,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
]);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async getChartRaw(span: 'hour' | 'day', amount: number, cursor: Date | null, group: string | null = null): Promise<ChartResult<T>> {
|
||||
const [y, m, d, h, _m, _s, _ms] = cursor ? Chart.parseDate(subtractTime(addTime(cursor, 1, span), 1)) : Chart.getCurrentDate();
|
||||
const [y2, m2, d2, h2] = cursor ? Chart.parseDate(addTime(cursor, 1, span)) : [] as never;
|
||||
@ -685,7 +669,6 @@ export default abstract class Chart<T extends Schema> {
|
||||
return res;
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async getChart(span: 'hour' | 'day', amount: number, cursor: Date | null, group: string | null = null): Promise<Unflatten<ChartResult<T>>> {
|
||||
const result = await this.getChartRaw(span, amount, cursor, group);
|
||||
const object = {};
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { entity as FederationChart } from './charts/entities/federation';
|
||||
import { entity as NotesChart } from './charts/entities/notes';
|
||||
import { entity as UsersChart } from './charts/entities/users';
|
||||
import { entity as ActiveUsersChart } from './charts/entities/active-users';
|
||||
import { entity as InstanceChart } from './charts/entities/instance';
|
||||
import { entity as PerUserNotesChart } from './charts/entities/per-user-notes';
|
||||
import { entity as DriveChart } from './charts/entities/drive';
|
||||
import { entity as PerUserReactionsChart } from './charts/entities/per-user-reactions';
|
||||
import { entity as HashtagChart } from './charts/entities/hashtag';
|
||||
import { entity as PerUserFollowingChart } from './charts/entities/per-user-following';
|
||||
import { entity as PerUserDriveChart } from './charts/entities/per-user-drive';
|
||||
import { entity as ApRequestChart } from './charts/entities/ap-request';
|
||||
import { entity as FederationChart } from './charts/entities/federation.js';
|
||||
import { entity as NotesChart } from './charts/entities/notes.js';
|
||||
import { entity as UsersChart } from './charts/entities/users.js';
|
||||
import { entity as ActiveUsersChart } from './charts/entities/active-users.js';
|
||||
import { entity as InstanceChart } from './charts/entities/instance.js';
|
||||
import { entity as PerUserNotesChart } from './charts/entities/per-user-notes.js';
|
||||
import { entity as DriveChart } from './charts/entities/drive.js';
|
||||
import { entity as PerUserReactionsChart } from './charts/entities/per-user-reactions.js';
|
||||
import { entity as HashtagChart } from './charts/entities/hashtag.js';
|
||||
import { entity as PerUserFollowingChart } from './charts/entities/per-user-following.js';
|
||||
import { entity as PerUserDriveChart } from './charts/entities/per-user-drive.js';
|
||||
import { entity as ApRequestChart } from './charts/entities/ap-request.js';
|
||||
|
||||
export const entities = [
|
||||
FederationChart.hour, FederationChart.day,
|
||||
|
@ -1,17 +1,17 @@
|
||||
import { beforeShutdown } from '@/misc/before-shutdown';
|
||||
import { beforeShutdown } from '@/misc/before-shutdown.js';
|
||||
|
||||
import FederationChart from './charts/federation';
|
||||
import NotesChart from './charts/notes';
|
||||
import UsersChart from './charts/users';
|
||||
import ActiveUsersChart from './charts/active-users';
|
||||
import InstanceChart from './charts/instance';
|
||||
import PerUserNotesChart from './charts/per-user-notes';
|
||||
import DriveChart from './charts/drive';
|
||||
import PerUserReactionsChart from './charts/per-user-reactions';
|
||||
import HashtagChart from './charts/hashtag';
|
||||
import PerUserFollowingChart from './charts/per-user-following';
|
||||
import PerUserDriveChart from './charts/per-user-drive';
|
||||
import ApRequestChart from './charts/ap-request';
|
||||
import FederationChart from './charts/federation.js';
|
||||
import NotesChart from './charts/notes.js';
|
||||
import UsersChart from './charts/users.js';
|
||||
import ActiveUsersChart from './charts/active-users.js';
|
||||
import InstanceChart from './charts/instance.js';
|
||||
import PerUserNotesChart from './charts/per-user-notes.js';
|
||||
import DriveChart from './charts/drive.js';
|
||||
import PerUserReactionsChart from './charts/per-user-reactions.js';
|
||||
import HashtagChart from './charts/hashtag.js';
|
||||
import PerUserFollowingChart from './charts/per-user-following.js';
|
||||
import PerUserDriveChart from './charts/per-user-drive.js';
|
||||
import ApRequestChart from './charts/ap-request.js';
|
||||
|
||||
export const federationChart = new FederationChart();
|
||||
export const notesChart = new NotesChart();
|
||||
|
Reference in New Issue
Block a user