Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opensearchのインデックス周りを修正 #535

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions packages/backend/src/core/AdvancedSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,18 @@ export class AdvancedSearchService {
@bindThis
public async indexNote(note: MiNote, choices?: string[]): Promise<void> {
if (!this.opensearch) return;
if (note.searchableBy === 'private' && note.userHost !== null) return;
if (note.renote?.searchableBy === 'private' && note.renote.userHost !== null) return;
if (note.text === null && note.cw === null && note.searchableBy !== 'private') {
//リノートであり、ローカルユーザー
await this.index(this.renoteIndex, note.id, {
renoteId: note.renoteId,
userId: note.userId,
createdAt: this.idService.parse(note.id).date.getTime(),
});
return;
if (note.searchableBy === 'private' && note.userHost !== null) return;//リモートユーザーのprivateはインデックスしない

if (note.text === null && note.cw === null && note.fileIds.length === 0 && note.renoteId) { //リノートであり
if (note.userHost === null) {//ローカルユーザー
if (note.renote?.searchableBy === 'private') return;//リノート元のノートがprivateならインデックスしない
await this.index(this.renoteIndex, note.id, {
renoteId: note.renoteId,
userId: note.userId,
createdAt: this.idService.parse(note.id).date.getTime(),
});
return;
}
}
if (await this.redisClient.get('indexDeleted') !== null) {
return;
Expand Down Expand Up @@ -538,10 +540,10 @@ export class AdvancedSearchService {
.orWhere(new Brackets(qb2 => {
qb2
.where('note."userHost" IS NOT NULL')
.andWhere('note.searchableBy != \'private\' OR NULL');
.andWhere('note."searchableBy" != \'private\'')
.orWhere('note."searchableBy" IS NULL');
}));
}))
.andWhere('renote.searchableBy != \'private\' OR NULL')
.orderBy('note.id', 'ASC')
.limit(limit)
.getMany();
Expand Down Expand Up @@ -575,7 +577,6 @@ export class AdvancedSearchService {
.innerJoin('reac.user', 'user')
.leftJoin('reac.note', 'note')
.select(['reac', 'user.host', 'note.searchableBy'])
.andWhere('note.searchableBy != \'private\' OR NULL')
.orderBy('reac.id', 'ASC')
.limit(limit)
.getMany();
Expand Down Expand Up @@ -609,7 +610,6 @@ export class AdvancedSearchService {
.innerJoin('pv.user', 'user')
.select(['pv', 'user.host'])
.leftJoin('reac.note', 'note')
.andWhere('note.searchableBy != \'private\' OR NULL')
.andWhere('user.host IS NULL')
.orderBy('pv.id', 'ASC')
.limit(limit)
Expand Down Expand Up @@ -707,7 +707,7 @@ export class AdvancedSearchService {
if (await this.redisClient.get('indexDeleted') !== null) {
return;
}
if (note.text == null && note.cw == null) {
if (note.text == null && note.cw == null && note.fileIds.length === 0 && note.renoteId) {
//Renoteを消しとく
await this.unindexById(this.renoteIndex, note.id);
return;
Expand Down
22 changes: 9 additions & 13 deletions packages/backend/src/core/ReactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,14 @@ export class ReactionService {
// Create reaction
try {
await this.noteReactionsRepository.insert(record);
if (!(note.searchableBy === 'private' && note.userHost !== null)) {
await this.advancedSearchService.indexReaction({
id: record.id,
noteId: record.noteId,
userId: record.userId,
reaction: record.reaction,
remote: user.host === null ? false : true,
searchableBy: note.searchableBy ?? undefined,
});
}
await this.advancedSearchService.indexReaction({
id: record.id,
noteId: record.noteId,
userId: record.userId,
reaction: record.reaction,
remote: user.host === null ? false : true,
searchableBy: note.searchableBy ?? undefined,
});
} catch (e) {
if (isDuplicateKeyValueError(e)) {
const exists = await this.noteReactionsRepository.findOneByOrFail({
Expand Down Expand Up @@ -311,9 +309,7 @@ export class ReactionService {

// Delete reaction
const result = await this.noteReactionsRepository.delete(exist.id);
if (note.searchableBy !== 'private') {
await this.advancedSearchService.unindexReaction(exist.id, user.host !== null, note.id, exist.reaction);
}
await this.advancedSearchService.unindexReaction(exist.id, user.host !== null, note.id, exist.reaction);

if (result.affected !== 1) {
throw new IdentifiableError('60527ec9-b4cb-4a88-a6bd-32d3ad26817d', 'not reacted');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
userId: me.id,
choice: ps.choice,
});
if (!(note.searchableBy === 'private' && note.userHost === null)) {
if (note.userHost === null) {
this.advancedSearchService.indexVote(id, {
noteId: note.id,
userId: me.id,
Expand Down
Loading