feat: button in admin dash to index posts

This commit is contained in:
ThatOneCalculator 2023-03-29 13:30:02 -07:00
parent 48e0333e71
commit 32dd494424
No known key found for this signature in database
GPG key ID: 8703CACD01000000
3 changed files with 32 additions and 5 deletions

View file

@ -939,6 +939,9 @@ moveFromDescription: "This will set an alias of your old account so that you can
migrationConfirm: "Are you absolutely sure you want to migrate your acccount to {account}? Once you do this, you won't be able to reverse it, and you won't be able to use your account normally again.\nAlso, please ensure that you've set this current account as the account you're moving from."
defaultReaction: "Default emoji reaction for outgoing and incoming posts"
license: "License"
indexPost: "Index posts"
indexFrom: "Index from Post ID onwards (leave blank to index every post)"
indexNotice: "Now indexing. This will probably take a while, please don't restart your server for at least an hour."
_sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing NSFW media via Machine Learning. This will slightly increase the load on the server."

View file

@ -1,6 +1,7 @@
<template><MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :content-max="800" :margin-min="16" :margin-max="32">
<FormButton primary @click="indexPosts">{{ i18n.ts.indexNotes }}</FormButton>
<FormSuspense v-slot="{ result: database }" :p="databasePromiseFactory">
<MkKeyValue v-for="table in database" :key="table[0]" oneline style="margin: 1em 0;">
<template #key>{{ table[0] }}</template>
@ -13,6 +14,7 @@
<script lang="ts" setup>
import { } from 'vue';
import FormSuspense from '@/components/form/suspense.vue';
import FormButton from '@/components/MkButton.vue';
import MkKeyValue from '@/components/MkKeyValue.vue';
import * as os from '@/os';
import bytes from '@/filters/bytes';
@ -20,6 +22,30 @@ import number from '@/filters/number';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
async function indexPosts() {
const { canceled, result: index } = await os.inputText({
title: i18n.ts.indexFrom,
});
if (canceled) return;
if (index == null || index === "") {
await os.api('admin/search/index-all');
await os.alert({
type: 'info',
text: i18n.ts.indexNotice
});
}
else {
await os.api('admin/search/index-all', {
cursor: index
});
await os.alert({
type: 'info',
text: i18n.ts.indexNotice
});
}
}
const databasePromiseFactory = () => os.api('admin/get-table-stats').then(res => Object.entries(res).sort((a, b) => b[1].size - a[1].size));
const headerActions = $computed(() => []);

View file

@ -188,16 +188,14 @@ const menuDef = $computed(() => [{
text: i18n.ts.proxyAccount,
to: '/admin/proxy-account',
active: currentPage?.route.name === 'proxy-account',
}],
}] : []), {
title: i18n.ts.info,
items: [{
},
{
icon: 'ph-database ph-bold ph-lg',
text: i18n.ts.database,
to: '/admin/database',
active: currentPage?.route.name === 'database',
}],
}]);
}] : [])]);
watch(narrow, () => {
if (currentPage?.route.name == null && !narrow) {