1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-11-27 22:38:39 +09:00

using set instead of array for search (#7126)

* Resolve #6905

* Resolve #6905

* Resolve #6905
This commit is contained in:
Ehsan Javadynia 2021-01-30 05:39:46 +03:30 committed by GitHub
parent 100a131913
commit ff67fb337e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 18 deletions

View File

@ -1,13 +1,13 @@
export function isMutedUserRelated(note: any, mutedUserIds: string[]): boolean { export function isMutedUserRelated(note: any, mutedUserIds: Set<string>): boolean {
if (mutedUserIds.includes(note.userId)) { if (mutedUserIds.has(note.userId)) {
return true; return true;
} }
if (note.reply != null && mutedUserIds.includes(note.reply.userId)) { if (note.reply != null && mutedUserIds.has(note.reply.userId)) {
return true; return true;
} }
if (note.renote != null && mutedUserIds.includes(note.renote.userId)) { if (note.renote != null && mutedUserIds.has(note.renote.userId)) {
return true; return true;
} }

View File

@ -19,10 +19,10 @@ export default class extends Channel {
@autobind @autobind
private async onNote(note: PackedNote) { private async onNote(note: PackedNote) {
if (note.channelId) { if (note.channelId) {
if (!this.followingChannels.includes(note.channelId)) return; if (!this.followingChannels.has(note.channelId)) return;
} else { } else {
// その投稿のユーザーをフォローしていなかったら弾く // その投稿のユーザーをフォローしていなかったら弾く
if ((this.user!.id !== note.userId) && !this.following.includes(note.userId)) return; if ((this.user!.id !== note.userId) && !this.following.has(note.userId)) return;
} }
if (['followers', 'specified'].includes(note.visibility)) { if (['followers', 'specified'].includes(note.visibility)) {

View File

@ -29,9 +29,9 @@ export default class extends Channel {
// フォローしているチャンネルの投稿 の場合だけ // フォローしているチャンネルの投稿 の場合だけ
if (!( if (!(
(note.channelId == null && this.user!.id === note.userId) || (note.channelId == null && this.user!.id === note.userId) ||
(note.channelId == null && this.following.includes(note.userId)) || (note.channelId == null && this.following.has(note.userId)) ||
(note.channelId == null && ((note.user as PackedUser).host == null && note.visibility === 'public')) || (note.channelId == null && ((note.user as PackedUser).host == null && note.visibility === 'public')) ||
(note.channelId != null && this.followingChannels.includes(note.channelId)) (note.channelId != null && this.followingChannels.has(note.channelId))
)) return; )) return;
if (['followers', 'specified'].includes(note.visibility)) { if (['followers', 'specified'].includes(note.visibility)) {

View File

@ -27,7 +27,7 @@ export default class extends Channel {
private async onNote(note: PackedNote) { private async onNote(note: PackedNote) {
if ((note.user as PackedUser).host !== null) return; if ((note.user as PackedUser).host !== null) return;
if (note.visibility !== 'public') return; if (note.visibility !== 'public') return;
if (note.channelId != null && !this.followingChannels.includes(note.channelId)) return; if (note.channelId != null && !this.followingChannels.has(note.channelId)) return;
// リプライなら再pack // リプライなら再pack
if (note.replyId != null) { if (note.replyId != null) {

View File

@ -16,7 +16,7 @@ export default class extends Channel {
switch (type) { switch (type) {
case 'notification': { case 'notification': {
if (this.muting.includes(body.userId)) return; if (this.muting.has(body.userId)) return;
if (body.note && body.note.isHidden) { if (body.note && body.note.isHidden) {
body.note = await Notes.pack(body.note.id, this.user, { body.note = await Notes.pack(body.note.id, this.user, {
detail: true detail: true
@ -25,7 +25,7 @@ export default class extends Channel {
break; break;
} }
case 'mention': { case 'mention': {
if (this.muting.includes(body.userId)) return; if (this.muting.has(body.userId)) return;
if (body.isHidden) { if (body.isHidden) {
body = await Notes.pack(body.id, this.user, { body = await Notes.pack(body.id, this.user, {
detail: true detail: true

View File

@ -19,9 +19,9 @@ import { UserProfile } from '../../../models/entities/user-profile';
export default class Connection { export default class Connection {
public user?: User; public user?: User;
public userProfile?: UserProfile; public userProfile?: UserProfile;
public following: User['id'][] = []; public following: Set<User['id']> = new Set();
public muting: User['id'][] = []; public muting: Set<User['id']> = new Set();
public followingChannels: ChannelModel['id'][] = []; public followingChannels: Set<ChannelModel['id']> = new Set();
public token?: AccessToken; public token?: AccessToken;
private wsConnection: websocket.connection; private wsConnection: websocket.connection;
public subscriber: EventEmitter; public subscriber: EventEmitter;
@ -267,7 +267,7 @@ export default class Connection {
select: ['followeeId'] select: ['followeeId']
}); });
this.following = followings.map(x => x.followeeId); this.following = new Set<string>(followings.map(x => x.followeeId));
} }
@autobind @autobind
@ -279,7 +279,7 @@ export default class Connection {
select: ['muteeId'] select: ['muteeId']
}); });
this.muting = mutings.map(x => x.muteeId); this.muting = new Set<string>(mutings.map(x => x.muteeId));
} }
@autobind @autobind
@ -291,7 +291,7 @@ export default class Connection {
select: ['followeeId'] select: ['followeeId']
}); });
this.followingChannels = followings.map(x => x.followeeId); this.followingChannels = new Set<string>(followings.map(x => x.followeeId));
} }
@autobind @autobind

View File

@ -40,7 +40,7 @@ export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: U
_note.renote = await Notes.findOne(note.renoteId).then(ensure); _note.renote = await Notes.findOne(note.renoteId).then(ensure);
} }
if (isMutedUserRelated(_note, mutings.map(x => x.muteeId))) { if (isMutedUserRelated(_note, new Set<string>(mutings.map(x => x.muteeId)))) {
return; return;
} }