Skip to content

Commit

Permalink
enhance(backend): some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Oct 6, 2023
1 parent 132b014 commit 8741671
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 24 deletions.
5 changes: 2 additions & 3 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,8 @@ export class NoteCreateService implements OnApplicationShutdown {
});
}

// この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき
if (data.renote && (await this.noteEntityService.countSameRenotes(user.id, data.renote.id, note.id) === 0)) {
if (!user.isBot) this.incRenoteCount(data.renote);
if (data.renote && data.renote.userId !== user.id && !user.isBot) {
this.incRenoteCount(data.renote);
}

if (data.poll && data.poll.expiresAt) {
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/core/NoteDeleteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ export class NoteDeleteService {
const deletedAt = new Date();
const cascadingNotes = await this.findCascadingNotes(note);

// この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき
if (note.renoteId && (await this.noteEntityService.countSameRenotes(user.id, note.renoteId, note.id)) === 0) {
this.notesRepository.decrement({ id: note.renoteId }, 'renoteCount', 1);
}

if (note.replyId) {
await this.notesRepository.decrement({ id: note.replyId }, 'repliesCount', 1);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/ReactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class ReactionService {
.execute();

// 30%の確率でハイライト用ランキング更新
if (Math.random() < 0.3) {
if (Math.random() < 0.3 && note.userId !== user.id) {
if (note.channelId != null) {
this.featuredService.updateInChannelNotesRanking(note.id, note.channelId, 1);
} else if (note.visibility === 'public' && note.userHost == null) {
Expand Down
15 changes: 0 additions & 15 deletions packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,4 @@ export class NoteEntityService implements OnModuleInit {
}
return emojis.filter(x => x.name != null && x.host != null) as { name: string; host: string; }[];
}

@bindThis
public async countSameRenotes(userId: string, renoteId: string, excludeNoteId: string | undefined): Promise<number> {
// 指定したユーザーの指定したノートのリノートがいくつあるか数える
const query = this.notesRepository.createQueryBuilder('note')
.where('note.userId = :userId', { userId })
.andWhere('note.renoteId = :renoteId', { renoteId });

// 指定した投稿を除く
if (excludeNoteId) {
query.andWhere('note.id != :excludeNoteId', { excludeNoteId });
}

return await query.getCount();
}
}

0 comments on commit 8741671

Please sign in to comment.