mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat: Auto add new users and statuses to Meilisearch
This commit is contained in:
parent
553b558c1a
commit
b5913b163c
3 changed files with 38 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ import { getConfig } from "@config";
|
|||
import chalk from "chalk";
|
||||
import { client } from "~database/datasource";
|
||||
import { Meilisearch } from "meilisearch";
|
||||
import type { Status, User } from "@prisma/client";
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
|
|
@ -48,6 +49,32 @@ export enum MeiliIndexType {
|
|||
Statuses = "statuses",
|
||||
}
|
||||
|
||||
export const addStausToMeilisearch = async (status: Status) => {
|
||||
if (!config.meilisearch.enabled) return;
|
||||
|
||||
await meilisearch.index(MeiliIndexType.Statuses).addDocuments([
|
||||
{
|
||||
id: status.id,
|
||||
content: status.content,
|
||||
createdAt: status.createdAt,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
export const addUserToMeilisearch = async (user: User) => {
|
||||
if (!config.meilisearch.enabled) return;
|
||||
|
||||
await meilisearch.index(MeiliIndexType.Accounts).addDocuments([
|
||||
{
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
displayName: user.displayName,
|
||||
note: user.note,
|
||||
createdAt: user.createdAt,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
export const getNthDatabaseAccountBatch = (
|
||||
n: number,
|
||||
batchSize = 1000
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue