From e106092f5d4c79ec8d6ad53431ecb46839afe26c Mon Sep 17 00:00:00 2001 From: Nafu Satsuki Date: Thu, 29 Feb 2024 15:22:37 +0900 Subject: [PATCH] =?UTF-8?q?enhance:=20=E5=85=A8=E3=83=AD=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=83=AB=E3=83=8E=E3=83=BC=E3=83=88=E3=82=92=E5=BC=B7=E5=88=B6?= =?UTF-8?q?=E7=9A=84=E3=81=AB=E3=82=A4=E3=83=B3=E3=83=87=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=82=B9=E3=81=95=E3=81=9B=E3=82=8BAPI=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/SearchService.ts | 18 ++++++++++++ .../backend/src/server/api/EndpointsModule.ts | 4 +++ packages/backend/src/server/api/endpoints.ts | 2 ++ .../server/api/endpoints/admin/full-index.ts | 29 +++++++++++++++++++ .../src/pages/admin/other-settings.vue | 9 ++++++ 5 files changed, 62 insertions(+) create mode 100644 packages/backend/src/server/api/endpoints/admin/full-index.ts diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 697a17d2eeb0..fe33e8efb0e7 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -233,6 +233,24 @@ export class SearchService { } } + @bindThis + public async fullIndexNote(): Promise { + const notesCount = await this.notesRepository.createQueryBuilder('note').where('note.userHost IS NULL').getCount(); + const take = 100; + for (let index = 0; index < notesCount; index = index + take) { + const notes = await this.notesRepository + .createQueryBuilder('note') + .orderBy('note.id', 'ASC') + .where('note.userHost IS NULL') + .take(take) + .skip(index) + .getMany(); + notes.forEach(note => { + this.indexNote(note); + }); + } + } + @bindThis public async unindexNote(note: MiNote): Promise { if (!['home', 'public'].includes(note.visibility)) return; diff --git a/packages/backend/src/server/api/EndpointsModule.ts b/packages/backend/src/server/api/EndpointsModule.ts index 0109e3465426..440c5ab50039 100644 --- a/packages/backend/src/server/api/EndpointsModule.ts +++ b/packages/backend/src/server/api/EndpointsModule.ts @@ -64,6 +64,7 @@ import * as ep___admin_relays_remove from './endpoints/admin/relays/remove.js'; import * as ep___admin_resetPassword from './endpoints/admin/reset-password.js'; import * as ep___admin_resolveAbuseUserReport from './endpoints/admin/resolve-abuse-user-report.js'; import * as ep___admin_sendEmail from './endpoints/admin/send-email.js'; +import * as ep___admin_fullIndex from './endpoints/admin/full-index.js'; import * as ep___admin_serverInfo from './endpoints/admin/server-info.js'; import * as ep___admin_showModerationLogs from './endpoints/admin/show-moderation-logs.js'; import * as ep___admin_showUser from './endpoints/admin/show-user.js'; @@ -441,6 +442,7 @@ const $admin_relays_remove: Provider = { provide: 'ep:admin/relays/remove', useC const $admin_resetPassword: Provider = { provide: 'ep:admin/reset-password', useClass: ep___admin_resetPassword.default }; const $admin_resolveAbuseUserReport: Provider = { provide: 'ep:admin/resolve-abuse-user-report', useClass: ep___admin_resolveAbuseUserReport.default }; const $admin_sendEmail: Provider = { provide: 'ep:admin/send-email', useClass: ep___admin_sendEmail.default }; +const $admin_fullIndex: Provider = { provide: 'ep:admin/full-index', useClass: ep___admin_fullIndex.default }; const $admin_serverInfo: Provider = { provide: 'ep:admin/server-info', useClass: ep___admin_serverInfo.default }; const $admin_showModerationLogs: Provider = { provide: 'ep:admin/show-moderation-logs', useClass: ep___admin_showModerationLogs.default }; const $admin_showUser: Provider = { provide: 'ep:admin/show-user', useClass: ep___admin_showUser.default }; @@ -822,6 +824,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__ $admin_resetPassword, $admin_resolveAbuseUserReport, $admin_sendEmail, + $admin_fullIndex, $admin_serverInfo, $admin_showModerationLogs, $admin_showUser, @@ -1197,6 +1200,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__ $admin_resetPassword, $admin_resolveAbuseUserReport, $admin_sendEmail, + $admin_fullIndex, $admin_serverInfo, $admin_showModerationLogs, $admin_showUser, diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 6fcb7f1489c8..48de29ac071b 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -64,6 +64,7 @@ import * as ep___admin_relays_remove from './endpoints/admin/relays/remove.js'; import * as ep___admin_resetPassword from './endpoints/admin/reset-password.js'; import * as ep___admin_resolveAbuseUserReport from './endpoints/admin/resolve-abuse-user-report.js'; import * as ep___admin_sendEmail from './endpoints/admin/send-email.js'; +import * as ep___admin_fullIndex from './endpoints/admin/full-index.js'; import * as ep___admin_serverInfo from './endpoints/admin/server-info.js'; import * as ep___admin_showModerationLogs from './endpoints/admin/show-moderation-logs.js'; import * as ep___admin_showUser from './endpoints/admin/show-user.js'; @@ -439,6 +440,7 @@ const eps = [ ['admin/reset-password', ep___admin_resetPassword], ['admin/resolve-abuse-user-report', ep___admin_resolveAbuseUserReport], ['admin/send-email', ep___admin_sendEmail], + ['admin/full-index', ep___admin_fullIndex], ['admin/server-info', ep___admin_serverInfo], ['admin/show-moderation-logs', ep___admin_showModerationLogs], ['admin/show-user', ep___admin_showUser], diff --git a/packages/backend/src/server/api/endpoints/admin/full-index.ts b/packages/backend/src/server/api/endpoints/admin/full-index.ts new file mode 100644 index 000000000000..c11cb6be2a32 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/admin/full-index.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@nestjs/common'; +import { Endpoint } from '@/server/api/endpoint-base.js'; +import { SearchService } from '@/core/SearchService.js'; + +export const meta = { + tags: ['admin'], + + requireCredential: true, + requireAdmin: true, +} as const; + +export const paramDef = { + type: 'object', + properties: { + }, + required: [], +} as const; + +// eslint-disable-next-line import/no-default-export +@Injectable() +export default class extends Endpoint { + constructor( + private searchService: SearchService, + ) { + super(meta, paramDef, async (ps, me) => { + await this.searchService.fullIndexNote(); + }); + } +} diff --git a/packages/frontend/src/pages/admin/other-settings.vue b/packages/frontend/src/pages/admin/other-settings.vue index 651f0ef93692..a87b1db909a6 100644 --- a/packages/frontend/src/pages/admin/other-settings.vue +++ b/packages/frontend/src/pages/admin/other-settings.vue @@ -36,6 +36,10 @@ SPDX-License-Identifier: AGPL-3.0-only + +
+ Create Full Index +
@@ -52,6 +56,7 @@ import { fetchInstance } from '@/instance.js'; import { i18n } from '@/i18n.js'; import { definePageMetadata } from '@/scripts/page-metadata.js'; import MkSwitch from '@/components/MkSwitch.vue'; +import MkButton from '@/components/MkButton.vue'; const enableServerMachineStats = ref(false); const enableIdenticonGeneration = ref(false); @@ -77,6 +82,10 @@ function save() { }); } +function fullIndex() { + os.apiWithDialog('admin/full-index'); +} + const headerActions = computed(() => [{ asFullButton: true, icon: 'ti ti-check',