FoundKey/packages/backend/src/services/note/index.ts
Johann150 704651e057
Some checks failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/test Pipeline failed
refactor mutedWordsCache and index to separate file
2023-05-29 22:29:37 +02:00

33 lines
952 B
TypeScript

import es from '@/db/elasticsearch.js';
import config from '@/config/index.js';
import { Note } from '@/models/entities/note.js';
import { UserProfiles } from '@/models/index.js';
import { normalizeForSearch } from '@/misc/normalize-for-search.js';
import { Cache } from '@/misc/cache.js';
import { UserProfile } from '@/models/entities/user-profile.js';
import { MINUTE } from '@/const.js';
export const mutedWordsCache = new Cache<{ userId: UserProfile['userId']; mutedWords: UserProfile['mutedWords']; }[]>(
5 * MINUTE,
() => UserProfiles.find({
where: {
enableWordMute: true,
},
select: ['userId', 'mutedWords'],
}),
);
export function index(note: Note): void {
if (note.text == null || config.elasticsearch == null) return;
es.index({
index: config.elasticsearch.index || 'misskey_note',
id: note.id.toString(),
body: {
text: normalizeForSearch(note.text),
userId: note.userId,
userHost: note.userHost,
},
});
}