summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/chart
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-01-01 17:45:49 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-01-01 17:45:49 +0900
commit969e9df889367159e64fcabadfd2150b1dfd685d (patch)
treebbc864061afa5f49dede6c404d48999bfe783fe2 /packages/backend/src/core/chart
parentclean up (diff)
downloadsharkey-969e9df889367159e64fcabadfd2150b1dfd685d.tar.gz
sharkey-969e9df889367159e64fcabadfd2150b1dfd685d.tar.bz2
sharkey-969e9df889367159e64fcabadfd2150b1dfd685d.zip
feat: add per user pv chart
Diffstat (limited to 'packages/backend/src/core/chart')
-rw-r--r--packages/backend/src/core/chart/ChartManagementService.ts5
-rw-r--r--packages/backend/src/core/chart/charts/entities/per-user-pv.ts12
-rw-r--r--packages/backend/src/core/chart/charts/per-user-pv.ts51
-rw-r--r--packages/backend/src/core/chart/entities.ts2
4 files changed, 69 insertions, 1 deletions
diff --git a/packages/backend/src/core/chart/ChartManagementService.ts b/packages/backend/src/core/chart/ChartManagementService.ts
index 13ee06c6c5..37de30b71c 100644
--- a/packages/backend/src/core/chart/ChartManagementService.ts
+++ b/packages/backend/src/core/chart/ChartManagementService.ts
@@ -1,11 +1,13 @@
import { Injectable, Inject } from '@nestjs/common';
+import { bindThis } from '@/decorators.js';
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 PerUserPvChart from './charts/per-user-pv.js';
import DriveChart from './charts/drive.js';
import PerUserReactionsChart from './charts/per-user-reactions.js';
import HashtagChart from './charts/hashtag.js';
@@ -13,7 +15,6 @@ 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 {
@@ -27,6 +28,7 @@ export class ChartManagementService implements OnApplicationShutdown {
private activeUsersChart: ActiveUsersChart,
private instanceChart: InstanceChart,
private perUserNotesChart: PerUserNotesChart,
+ private perUserPvChart: PerUserPvChart,
private driveChart: DriveChart,
private perUserReactionsChart: PerUserReactionsChart,
private hashtagChart: HashtagChart,
@@ -41,6 +43,7 @@ export class ChartManagementService implements OnApplicationShutdown {
this.activeUsersChart,
this.instanceChart,
this.perUserNotesChart,
+ this.perUserPvChart,
this.driveChart,
this.perUserReactionsChart,
this.hashtagChart,
diff --git a/packages/backend/src/core/chart/charts/entities/per-user-pv.ts b/packages/backend/src/core/chart/charts/entities/per-user-pv.ts
new file mode 100644
index 0000000000..64c8ed1fb1
--- /dev/null
+++ b/packages/backend/src/core/chart/charts/entities/per-user-pv.ts
@@ -0,0 +1,12 @@
+import Chart from '../../core.js';
+
+export const name = 'perUserPv';
+
+export const schema = {
+ 'upv.user': { uniqueIncrement: true, range: 'small' },
+ 'pv.user': { range: 'small' },
+ 'upv.visitor': { uniqueIncrement: true, range: 'small' },
+ 'pv.visitor': { range: 'small' },
+} as const;
+
+export const entity = Chart.schemaToEntity(name, schema, true);
diff --git a/packages/backend/src/core/chart/charts/per-user-pv.ts b/packages/backend/src/core/chart/charts/per-user-pv.ts
new file mode 100644
index 0000000000..53c89d8a9a
--- /dev/null
+++ b/packages/backend/src/core/chart/charts/per-user-pv.ts
@@ -0,0 +1,51 @@
+import { Injectable, Inject } from '@nestjs/common';
+import { DataSource } from 'typeorm';
+import type { User } from '@/models/entities/User.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/per-user-pv.js';
+import type { KVs } from '../core.js';
+
+/**
+ * ユーザーごとのプロフィール被閲覧数に関するチャート
+ */
+// eslint-disable-next-line import/no-default-export
+@Injectable()
+export default class PerUserPvChart extends Chart<typeof schema> {
+ constructor(
+ @Inject(DI.db)
+ private db: DataSource,
+
+ private appLockService: AppLockService,
+ private chartLoggerService: ChartLoggerService,
+ ) {
+ super(db, (k) => appLockService.getChartInsertLock(k), chartLoggerService.logger, name, schema, true);
+ }
+
+ protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
+ return {};
+ }
+
+ protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
+ return {};
+ }
+
+ @bindThis
+ public async commitByUser(user: { id: User['id'] }, key: string): Promise<void> {
+ await this.commit({
+ 'upv.user': [key],
+ 'pv.user': 1,
+ }, user.id);
+ }
+
+ @bindThis
+ public async commitByVisitor(user: { id: User['id'] }, key: string): Promise<void> {
+ await this.commit({
+ 'upv.visitor': [key],
+ 'pv.visitor': 1,
+ }, user.id);
+ }
+}
diff --git a/packages/backend/src/core/chart/entities.ts b/packages/backend/src/core/chart/entities.ts
index a9eeabd639..c2759e8b3c 100644
--- a/packages/backend/src/core/chart/entities.ts
+++ b/packages/backend/src/core/chart/entities.ts
@@ -4,6 +4,7 @@ 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 PerUserPvChart } from './charts/entities/per-user-pv.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';
@@ -23,6 +24,7 @@ export const entities = [
ActiveUsersChart.hour, ActiveUsersChart.day,
InstanceChart.hour, InstanceChart.day,
PerUserNotesChart.hour, PerUserNotesChart.day,
+ PerUserPvChart.hour, PerUserPvChart.day,
DriveChart.hour, DriveChart.day,
PerUserReactionsChart.hour, PerUserReactionsChart.day,
HashtagChart.hour, HashtagChart.day,