Skip to content

Commit

Permalink
enhance: 全ローカルノートを強制的にインデックスさせるAPIの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
nafu-at committed Feb 29, 2024
1 parent 75f636d commit e106092
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/backend/src/core/SearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ export class SearchService {
}
}

@bindThis
public async fullIndexNote(): Promise<void> {
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<void> {
if (!['home', 'public'].includes(note.visibility)) return;
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/server/api/EndpointsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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],
Expand Down
29 changes: 29 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/full-index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof meta, typeof paramDef> {
constructor(
private searchService: SearchService,
) {
super(meta, paramDef, async (ps, me) => {
await this.searchService.fullIndexNote();
});
}
}
9 changes: 9 additions & 0 deletions packages/frontend/src/pages/admin/other-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #caption>{{ i18n.ts.turnOffToImprovePerformance }}</template>
</MkSwitch>
</div>

<div class="_panel" style="padding: 16px;">
<MkButton class="button" inline danger @click="fullIndex()"> Create Full Index </MkButton>
</div>
</div>
</FormSuspense>
</MkSpacer>
Expand All @@ -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<boolean>(false);
const enableIdenticonGeneration = ref<boolean>(false);
Expand All @@ -77,6 +82,10 @@ function save() {
});
}

function fullIndex() {
os.apiWithDialog('admin/full-index');
}

const headerActions = computed(() => [{
asFullButton: true,
icon: 'ti ti-check',
Expand Down

0 comments on commit e106092

Please sign in to comment.