Skip to content

Commit

Permalink
opensearchのインデックス周りを修正 (kokonect-link#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
penginn-net authored Nov 8, 2024
1 parent bdb22e2 commit f34b0d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
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 @@ -533,10 +535,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 @@ -570,7 +572,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 @@ -604,7 +605,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 @@ -702,7 +702,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

0 comments on commit f34b0d5

Please sign in to comment.