diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-01 17:45:49 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-01 17:45:49 +0900 |
| commit | 969e9df889367159e64fcabadfd2150b1dfd685d (patch) | |
| tree | bbc864061afa5f49dede6c404d48999bfe783fe2 /packages/backend/src/core | |
| parent | clean up (diff) | |
| download | sharkey-969e9df889367159e64fcabadfd2150b1dfd685d.tar.gz sharkey-969e9df889367159e64fcabadfd2150b1dfd685d.tar.bz2 sharkey-969e9df889367159e64fcabadfd2150b1dfd685d.zip | |
feat: add per user pv chart
Diffstat (limited to 'packages/backend/src/core')
5 files changed, 75 insertions, 1 deletions
diff --git a/packages/backend/src/core/CoreModule.ts b/packages/backend/src/core/CoreModule.ts index 085addaa05..7c6d12abf8 100644 --- a/packages/backend/src/core/CoreModule.ts +++ b/packages/backend/src/core/CoreModule.ts @@ -57,6 +57,7 @@ import UsersChart from './chart/charts/users.js'; import ActiveUsersChart from './chart/charts/active-users.js'; import InstanceChart from './chart/charts/instance.js'; import PerUserNotesChart from './chart/charts/per-user-notes.js'; +import PerUserPvChart from './chart/charts/per-user-pv.js'; import DriveChart from './chart/charts/drive.js'; import PerUserReactionsChart from './chart/charts/per-user-reactions.js'; import HashtagChart from './chart/charts/hashtag.js'; @@ -176,6 +177,7 @@ const $UsersChart: Provider = { provide: 'UsersChart', useExisting: UsersChart } const $ActiveUsersChart: Provider = { provide: 'ActiveUsersChart', useExisting: ActiveUsersChart }; const $InstanceChart: Provider = { provide: 'InstanceChart', useExisting: InstanceChart }; const $PerUserNotesChart: Provider = { provide: 'PerUserNotesChart', useExisting: PerUserNotesChart }; +const $PerUserPvChart: Provider = { provide: 'PerUserPvChart', useExisting: PerUserPvChart }; const $DriveChart: Provider = { provide: 'DriveChart', useExisting: DriveChart }; const $PerUserReactionsChart: Provider = { provide: 'PerUserReactionsChart', useExisting: PerUserReactionsChart }; const $HashtagChart: Provider = { provide: 'HashtagChart', useExisting: HashtagChart }; @@ -298,6 +300,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting ActiveUsersChart, InstanceChart, PerUserNotesChart, + PerUserPvChart, DriveChart, PerUserReactionsChart, HashtagChart, @@ -414,6 +417,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting $ActiveUsersChart, $InstanceChart, $PerUserNotesChart, + $PerUserPvChart, $DriveChart, $PerUserReactionsChart, $HashtagChart, @@ -530,6 +534,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting ActiveUsersChart, InstanceChart, PerUserNotesChart, + PerUserPvChart, DriveChart, PerUserReactionsChart, HashtagChart, @@ -645,6 +650,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting $ActiveUsersChart, $InstanceChart, $PerUserNotesChart, + $PerUserPvChart, $DriveChart, $PerUserReactionsChart, $HashtagChart, 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, |