summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/chart
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-12-04 15:03:09 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-12-04 15:03:09 +0900
commitbbb49457f9fb5d46402e913c92ebf77722cad6ff (patch)
tree8ef285bcbab2c3a4a89d0a624a802d76a2864fed /packages/backend/src/core/chart
parent:art: (diff)
downloadsharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.gz
sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.bz2
sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.zip
refactor: introduce bindThis decorator to bind this automaticaly
Diffstat (limited to 'packages/backend/src/core/chart')
-rw-r--r--packages/backend/src/core/chart/ChartLoggerService.ts1
-rw-r--r--packages/backend/src/core/chart/ChartManagementService.ts2
-rw-r--r--packages/backend/src/core/chart/charts/active-users.ts3
-rw-r--r--packages/backend/src/core/chart/charts/ap-request.ts4
-rw-r--r--packages/backend/src/core/chart/charts/drive.ts2
-rw-r--r--packages/backend/src/core/chart/charts/federation.ts3
-rw-r--r--packages/backend/src/core/chart/charts/hashtag.ts2
-rw-r--r--packages/backend/src/core/chart/charts/instance.ts8
-rw-r--r--packages/backend/src/core/chart/charts/notes.ts2
-rw-r--r--packages/backend/src/core/chart/charts/per-user-drive.ts2
-rw-r--r--packages/backend/src/core/chart/charts/per-user-following.ts2
-rw-r--r--packages/backend/src/core/chart/charts/per-user-notes.ts2
-rw-r--r--packages/backend/src/core/chart/charts/per-user-reactions.ts2
-rw-r--r--packages/backend/src/core/chart/charts/test-grouped.ts2
-rw-r--r--packages/backend/src/core/chart/charts/test-intersection.ts3
-rw-r--r--packages/backend/src/core/chart/charts/test-unique.ts2
-rw-r--r--packages/backend/src/core/chart/charts/test.ts3
-rw-r--r--packages/backend/src/core/chart/charts/users.ts2
-rw-r--r--packages/backend/src/core/chart/core.ts11
19 files changed, 58 insertions, 0 deletions
diff --git a/packages/backend/src/core/chart/ChartLoggerService.ts b/packages/backend/src/core/chart/ChartLoggerService.ts
index 544a006ac9..d392c6d595 100644
--- a/packages/backend/src/core/chart/ChartLoggerService.ts
+++ b/packages/backend/src/core/chart/ChartLoggerService.ts
@@ -1,6 +1,7 @@
import { Inject, Injectable } from '@nestjs/common';
import type Logger from '@/logger.js';
import { LoggerService } from '@/core/LoggerService.js';
+import { bindThis } from '@/decorators.js';
@Injectable()
export class ChartLoggerService {
diff --git a/packages/backend/src/core/chart/ChartManagementService.ts b/packages/backend/src/core/chart/ChartManagementService.ts
index 6476cd6843..13ee06c6c5 100644
--- a/packages/backend/src/core/chart/ChartManagementService.ts
+++ b/packages/backend/src/core/chart/ChartManagementService.ts
@@ -13,6 +13,7 @@ import PerUserFollowingChart from './charts/per-user-following.js';
import PerUserDriveChart from './charts/per-user-drive.js';
import ApRequestChart from './charts/ap-request.js';
import type { OnApplicationShutdown } from '@nestjs/common';
+import { bindThis } from '@/decorators.js';
@Injectable()
export class ChartManagementService implements OnApplicationShutdown {
@@ -49,6 +50,7 @@ export class ChartManagementService implements OnApplicationShutdown {
];
}
+ @bindThis
public async run() {
// 20分おきにメモリ情報をDBに書き込み
this.saveIntervalId = setInterval(() => {
diff --git a/packages/backend/src/core/chart/charts/active-users.ts b/packages/backend/src/core/chart/charts/active-users.ts
index 40c60910ea..bc0ba25cbb 100644
--- a/packages/backend/src/core/chart/charts/active-users.ts
+++ b/packages/backend/src/core/chart/charts/active-users.ts
@@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
import { AppLockService } from '@/core/AppLockService.js';
import type { User } from '@/models/entities/User.js';
import { DI } from '@/di-symbols.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/active-users.js';
@@ -36,6 +37,7 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async read(user: { id: User['id'], host: null, createdAt: User['createdAt'] }): Promise<void> {
await this.commit({
'read': [user.id],
@@ -48,6 +50,7 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
});
}
+ @bindThis
public async write(user: { id: User['id'], host: null, createdAt: User['createdAt'] }): Promise<void> {
await this.commit({
'write': [user.id],
diff --git a/packages/backend/src/core/chart/charts/ap-request.ts b/packages/backend/src/core/chart/charts/ap-request.ts
index 4b91fbbf18..ce377460c8 100644
--- a/packages/backend/src/core/chart/charts/ap-request.ts
+++ b/packages/backend/src/core/chart/charts/ap-request.ts
@@ -2,6 +2,7 @@ import { Injectable, Inject } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/ap-request.js';
@@ -31,18 +32,21 @@ export default class ApRequestChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async deliverSucc(): Promise<void> {
await this.commit({
'deliverSucceeded': 1,
});
}
+ @bindThis
public async deliverFail(): Promise<void> {
await this.commit({
'deliverFailed': 1,
});
}
+ @bindThis
public async inbox(): Promise<void> {
await this.commit({
'inboxReceived': 1,
diff --git a/packages/backend/src/core/chart/charts/drive.ts b/packages/backend/src/core/chart/charts/drive.ts
index 494dfbbe57..da36b944f5 100644
--- a/packages/backend/src/core/chart/charts/drive.ts
+++ b/packages/backend/src/core/chart/charts/drive.ts
@@ -3,6 +3,7 @@ import { Not, IsNull, DataSource } from 'typeorm';
import type { DriveFile } from '@/models/entities/DriveFile.js';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/drive.js';
@@ -32,6 +33,7 @@ export default class DriveChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(file: DriveFile, isAdditional: boolean): Promise<void> {
const fileSizeKb = file.size / 1000;
await this.commit(file.userHost === null ? {
diff --git a/packages/backend/src/core/chart/charts/federation.ts b/packages/backend/src/core/chart/charts/federation.ts
index 21e4cedea3..d9234e8028 100644
--- a/packages/backend/src/core/chart/charts/federation.ts
+++ b/packages/backend/src/core/chart/charts/federation.ts
@@ -4,6 +4,7 @@ import type { FollowingsRepository, InstancesRepository } from '@/models/index.j
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import { MetaService } from '@/core/MetaService.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/federation.js';
@@ -107,6 +108,7 @@ export default class FederationChart extends Chart<typeof schema> {
};
}
+ @bindThis
public async deliverd(host: string, succeeded: boolean): Promise<void> {
await this.commit(succeeded ? {
'deliveredInstances': [host],
@@ -115,6 +117,7 @@ export default class FederationChart extends Chart<typeof schema> {
});
}
+ @bindThis
public async inbox(host: string): Promise<void> {
await this.commit({
'inboxInstances': [host],
diff --git a/packages/backend/src/core/chart/charts/hashtag.ts b/packages/backend/src/core/chart/charts/hashtag.ts
index 8b8c795cfd..3899b41363 100644
--- a/packages/backend/src/core/chart/charts/hashtag.ts
+++ b/packages/backend/src/core/chart/charts/hashtag.ts
@@ -4,6 +4,7 @@ import type { User } from '@/models/entities/User.js';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/hashtag.js';
@@ -34,6 +35,7 @@ export default class HashtagChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(hashtag: string, user: { id: User['id'], host: User['host'] }): Promise<void> {
await this.commit({
'local.users': this.userEntityService.isLocalUser(user) ? [user.id] : [],
diff --git a/packages/backend/src/core/chart/charts/instance.ts b/packages/backend/src/core/chart/charts/instance.ts
index 2e0f4c7126..8ca88d80e3 100644
--- a/packages/backend/src/core/chart/charts/instance.ts
+++ b/packages/backend/src/core/chart/charts/instance.ts
@@ -6,6 +6,7 @@ import type { Note } from '@/models/entities/Note.js';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import { UtilityService } from '@/core/UtilityService.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/instance.js';
@@ -68,12 +69,14 @@ export default class InstanceChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async requestReceived(host: string): Promise<void> {
await this.commit({
'requests.received': 1,
}, this.utilityService.toPuny(host));
}
+ @bindThis
public async requestSent(host: string, isSucceeded: boolean): Promise<void> {
await this.commit({
'requests.succeeded': isSucceeded ? 1 : 0,
@@ -81,6 +84,7 @@ export default class InstanceChart extends Chart<typeof schema> {
}, this.utilityService.toPuny(host));
}
+ @bindThis
public async newUser(host: string): Promise<void> {
await this.commit({
'users.total': 1,
@@ -88,6 +92,7 @@ export default class InstanceChart extends Chart<typeof schema> {
}, this.utilityService.toPuny(host));
}
+ @bindThis
public async updateNote(host: string, note: Note, isAdditional: boolean): Promise<void> {
await this.commit({
'notes.total': isAdditional ? 1 : -1,
@@ -100,6 +105,7 @@ export default class InstanceChart extends Chart<typeof schema> {
}, this.utilityService.toPuny(host));
}
+ @bindThis
public async updateFollowing(host: string, isAdditional: boolean): Promise<void> {
await this.commit({
'following.total': isAdditional ? 1 : -1,
@@ -108,6 +114,7 @@ export default class InstanceChart extends Chart<typeof schema> {
}, this.utilityService.toPuny(host));
}
+ @bindThis
public async updateFollowers(host: string, isAdditional: boolean): Promise<void> {
await this.commit({
'followers.total': isAdditional ? 1 : -1,
@@ -116,6 +123,7 @@ export default class InstanceChart extends Chart<typeof schema> {
}, this.utilityService.toPuny(host));
}
+ @bindThis
public async updateDrive(file: DriveFile, isAdditional: boolean): Promise<void> {
const fileSizeKb = file.size / 1000;
await this.commit({
diff --git a/packages/backend/src/core/chart/charts/notes.ts b/packages/backend/src/core/chart/charts/notes.ts
index 2153cfe4b4..23dc248fec 100644
--- a/packages/backend/src/core/chart/charts/notes.ts
+++ b/packages/backend/src/core/chart/charts/notes.ts
@@ -4,6 +4,7 @@ import type { NotesRepository } from '@/models/index.js';
import type { Note } from '@/models/entities/Note.js';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/notes.js';
@@ -44,6 +45,7 @@ export default class NotesChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(note: Note, isAdditional: boolean): Promise<void> {
const prefix = note.userHost === null ? 'local' : 'remote';
diff --git a/packages/backend/src/core/chart/charts/per-user-drive.ts b/packages/backend/src/core/chart/charts/per-user-drive.ts
index a44460bb4e..ffba04b041 100644
--- a/packages/backend/src/core/chart/charts/per-user-drive.ts
+++ b/packages/backend/src/core/chart/charts/per-user-drive.ts
@@ -5,6 +5,7 @@ import type { DriveFile } from '@/models/entities/DriveFile.js';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/per-user-drive.js';
@@ -46,6 +47,7 @@ export default class PerUserDriveChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(file: DriveFile, isAdditional: boolean): Promise<void> {
const fileSizeKb = file.size / 1000;
await this.commit({
diff --git a/packages/backend/src/core/chart/charts/per-user-following.ts b/packages/backend/src/core/chart/charts/per-user-following.ts
index 5ea08a0872..aea6d44a9a 100644
--- a/packages/backend/src/core/chart/charts/per-user-following.ts
+++ b/packages/backend/src/core/chart/charts/per-user-following.ts
@@ -5,6 +5,7 @@ import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import type { FollowingsRepository } from '@/models/index.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/per-user-following.js';
@@ -55,6 +56,7 @@ export default class PerUserFollowingChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }, isFollow: boolean): Promise<void> {
const prefixFollower = this.userEntityService.isLocalUser(follower) ? 'local' : 'remote';
const prefixFollowee = this.userEntityService.isLocalUser(followee) ? 'local' : 'remote';
diff --git a/packages/backend/src/core/chart/charts/per-user-notes.ts b/packages/backend/src/core/chart/charts/per-user-notes.ts
index 5c14309d89..1e2a579dfa 100644
--- a/packages/backend/src/core/chart/charts/per-user-notes.ts
+++ b/packages/backend/src/core/chart/charts/per-user-notes.ts
@@ -5,6 +5,7 @@ import type { Note } from '@/models/entities/Note.js';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import type { NotesRepository } from '@/models/index.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/per-user-notes.js';
@@ -43,6 +44,7 @@ export default class PerUserNotesChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(user: { id: User['id'] }, note: Note, isAdditional: boolean): Promise<void> {
await this.commit({
'total': isAdditional ? 1 : -1,
diff --git a/packages/backend/src/core/chart/charts/per-user-reactions.ts b/packages/backend/src/core/chart/charts/per-user-reactions.ts
index 4160219720..7bc6d4b521 100644
--- a/packages/backend/src/core/chart/charts/per-user-reactions.ts
+++ b/packages/backend/src/core/chart/charts/per-user-reactions.ts
@@ -5,6 +5,7 @@ import type { Note } from '@/models/entities/Note.js';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/per-user-reactions.js';
@@ -35,6 +36,7 @@ export default class PerUserReactionsChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(user: { id: User['id'], host: User['host'] }, note: Note): Promise<void> {
const prefix = this.userEntityService.isLocalUser(user) ? 'local' : 'remote';
this.commit({
diff --git a/packages/backend/src/core/chart/charts/test-grouped.ts b/packages/backend/src/core/chart/charts/test-grouped.ts
index bc215f3942..128967bc65 100644
--- a/packages/backend/src/core/chart/charts/test-grouped.ts
+++ b/packages/backend/src/core/chart/charts/test-grouped.ts
@@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import Logger from '@/logger.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { name, schema } from './entities/test-grouped.js';
import type { KVs } from '../core.js';
@@ -35,6 +36,7 @@ export default class TestGroupedChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async increment(group: string): Promise<void> {
if (this.total[group] == null) this.total[group] = 0;
diff --git a/packages/backend/src/core/chart/charts/test-intersection.ts b/packages/backend/src/core/chart/charts/test-intersection.ts
index a074a7dded..6b4eed9062 100644
--- a/packages/backend/src/core/chart/charts/test-intersection.ts
+++ b/packages/backend/src/core/chart/charts/test-intersection.ts
@@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import Logger from '@/logger.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { name, schema } from './entities/test-intersection.js';
import type { KVs } from '../core.js';
@@ -31,12 +32,14 @@ export default class TestIntersectionChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async addA(key: string): Promise<void> {
await this.commit({
a: [key],
});
}
+ @bindThis
public async addB(key: string): Promise<void> {
await this.commit({
b: [key],
diff --git a/packages/backend/src/core/chart/charts/test-unique.ts b/packages/backend/src/core/chart/charts/test-unique.ts
index 4d3e2f2403..5d2b3f8ab1 100644
--- a/packages/backend/src/core/chart/charts/test-unique.ts
+++ b/packages/backend/src/core/chart/charts/test-unique.ts
@@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import Logger from '@/logger.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { name, schema } from './entities/test-unique.js';
import type { KVs } from '../core.js';
@@ -31,6 +32,7 @@ export default class TestUniqueChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async uniqueIncrement(key: string): Promise<void> {
await this.commit({
foo: [key],
diff --git a/packages/backend/src/core/chart/charts/test.ts b/packages/backend/src/core/chart/charts/test.ts
index 72caf79e0f..238351d8b3 100644
--- a/packages/backend/src/core/chart/charts/test.ts
+++ b/packages/backend/src/core/chart/charts/test.ts
@@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import Logger from '@/logger.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { name, schema } from './entities/test.js';
import type { KVs } from '../core.js';
@@ -35,6 +36,7 @@ export default class TestChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async increment(): Promise<void> {
this.total++;
@@ -44,6 +46,7 @@ export default class TestChart extends Chart<typeof schema> {
});
}
+ @bindThis
public async decrement(): Promise<void> {
this.total--;
diff --git a/packages/backend/src/core/chart/charts/users.ts b/packages/backend/src/core/chart/charts/users.ts
index f0359968eb..7bc3602439 100644
--- a/packages/backend/src/core/chart/charts/users.ts
+++ b/packages/backend/src/core/chart/charts/users.ts
@@ -5,6 +5,7 @@ import { AppLockService } from '@/core/AppLockService.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import type { UsersRepository } from '@/models/index.js';
+import { bindThis } from '@/decorators.js';
import Chart from '../core.js';
import { ChartLoggerService } from '../ChartLoggerService.js';
import { name, schema } from './entities/users.js';
@@ -46,6 +47,7 @@ export default class UsersChart extends Chart<typeof schema> {
return {};
}
+ @bindThis
public async update(user: { id: User['id'], host: User['host'] }, isAdditional: boolean): Promise<void> {
const prefix = this.userEntityService.isLocalUser(user) ? 'local' : 'remote';
diff --git a/packages/backend/src/core/chart/core.ts b/packages/backend/src/core/chart/core.ts
index cf5aa48884..2092b13b7e 100644
--- a/packages/backend/src/core/chart/core.ts
+++ b/packages/backend/src/core/chart/core.ts
@@ -8,6 +8,7 @@ import * as nestedProperty from 'nested-property';
import { EntitySchema, LessThan, Between } from 'typeorm';
import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/misc/prelude/time.js';
import type Logger from '@/logger.js';
+import { bindThis } from '@/decorators.js';
import type { Repository, DataSource } from 'typeorm';
const columnPrefix = '___' as const;
@@ -249,6 +250,7 @@ export default abstract class Chart<T extends Schema> {
this.repositoryForDay = db.getRepository<{ id: number; group?: string | null; date: number; }>(day);
}
+ @bindThis
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>)[]) {
@@ -257,6 +259,7 @@ export default abstract class Chart<T extends Schema> {
return kvs as KVs<T>;
}
+ @bindThis
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]])[]) {
@@ -269,6 +272,7 @@ export default abstract class Chart<T extends Schema> {
return log as KVs<T>;
}
+ @bindThis
private getLatestLog(group: string | null, span: 'hour' | 'day'): Promise<RawRecord<T> | null> {
const repository =
span === 'hour' ? this.repositoryForHour :
@@ -288,6 +292,7 @@ export default abstract class Chart<T extends Schema> {
/**
* 現在(=今のHour or Day)のログをデータベースから探して、あればそれを返し、なければ作成して返します。
*/
+ @bindThis
private async claimCurrentLog(group: string | null, span: 'hour' | 'day'): Promise<RawRecord<T>> {
const [y, m, d, h] = Chart.getCurrentDate();
@@ -380,6 +385,7 @@ export default abstract class Chart<T extends Schema> {
});
}
+ @bindThis
public async save(): Promise<void> {
if (this.buffer.length === 0) {
this.logger.info(`${this.name}: Write skipped`);
@@ -498,6 +504,7 @@ export default abstract class Chart<T extends Schema> {
update(logHour, logDay))));
}
+ @bindThis
public async tick(major: boolean, group: string | null = null): Promise<void> {
const data = major ? await this.tickMajor(group) : await this.tickMinor(group);
@@ -533,10 +540,12 @@ export default abstract class Chart<T extends Schema> {
update(logHour, logDay));
}
+ @bindThis
public resync(group: string | null = null): Promise<void> {
return this.tick(true, group);
}
+ @bindThis
public async clean(): Promise<void> {
const current = dateUTC(Chart.getCurrentDate());
@@ -572,6 +581,7 @@ export default abstract class Chart<T extends Schema> {
]);
}
+ @bindThis
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;
@@ -676,6 +686,7 @@ export default abstract class Chart<T extends Schema> {
return res;
}
+ @bindThis
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 = {};