From 0bddd0ceae8a94fa5835150bc127032af37e652d Mon Sep 17 00:00:00 2001 From: woxtu Date: Wed, 18 Oct 2023 09:54:18 +0900 Subject: [PATCH] Remove unnecessary nullish coalescing (#12058) --- packages/backend/src/core/CustomEmojiService.ts | 2 +- packages/backend/src/core/HashtagService.ts | 2 +- packages/backend/src/core/NoteCreateService.ts | 4 ++-- packages/backend/src/core/ReactionService.ts | 2 +- .../src/core/entities/DriveFileEntityService.ts | 10 +++++----- .../backend/src/core/entities/NoteEntityService.ts | 2 +- .../backend/src/core/entities/UserEntityService.ts | 6 +++--- packages/backend/src/daemons/ServerStatsService.ts | 3 +-- .../src/queue/processors/InboxProcessorService.ts | 2 +- .../src/server/api/stream/channels/home-timeline.ts | 2 +- .../src/server/api/stream/channels/hybrid-timeline.ts | 2 +- packages/backend/src/server/web/FeedService.ts | 2 +- 12 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts index 505c8e4269..9a8267b466 100644 --- a/packages/backend/src/core/CustomEmojiService.ts +++ b/packages/backend/src/core/CustomEmojiService.ts @@ -331,7 +331,7 @@ export class CustomEmojiService implements OnApplicationShutdown { const queryOrNull = async () => (await this.emojisRepository.findOneBy({ name, - host: host ?? IsNull(), + host, })) ?? null; const emoji = await this.cache.fetch(`${name} ${host}`, queryOrNull); diff --git a/packages/backend/src/core/HashtagService.ts b/packages/backend/src/core/HashtagService.ts index 1a2f37be39..d378999907 100644 --- a/packages/backend/src/core/HashtagService.ts +++ b/packages/backend/src/core/HashtagService.ts @@ -45,7 +45,7 @@ export class HashtagService { await this.updateHashtag(user, tag, true, true); } - for (const tag of (user.tags ?? []).filter(x => !tags.includes(x))) { + for (const tag of user.tags.filter(x => !tags.includes(x))) { await this.updateHashtag(user, tag, true, false); } } diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 3aefde50e0..7a47cba0e9 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -317,7 +317,7 @@ export class NoteCreateService implements OnApplicationShutdown { data.text = data.text.trim(); if (user.isCat) { - patsedText = patsedText ?? mfm.parse(data.text); + patsedText = mfm.parse(data.text); function nyaizeNode(node: mfm.MfmNode) { if (node.type === 'quote') return; if (node.type === 'text') { @@ -359,7 +359,7 @@ export class NoteCreateService implements OnApplicationShutdown { mentionedUsers = data.apMentions ?? await this.extractMentionedUsers(user, combinedTokens); } - tags = tags.filter(tag => Array.from(tag ?? '').length <= 128).splice(0, 32); + tags = tags.filter(tag => Array.from(tag).length <= 128).splice(0, 32); if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) { mentionedUsers.push(await this.usersRepository.findOneByOrFail({ id: data.reply!.userId })); diff --git a/packages/backend/src/core/ReactionService.ts b/packages/backend/src/core/ReactionService.ts index 49b465a0f8..1458e2b173 100644 --- a/packages/backend/src/core/ReactionService.ts +++ b/packages/backend/src/core/ReactionService.ts @@ -148,7 +148,7 @@ export class ReactionService { reaction = FALLBACK; } } else { - reaction = this.normalize(reaction ?? null); + reaction = this.normalize(reaction); } } diff --git a/packages/backend/src/core/entities/DriveFileEntityService.ts b/packages/backend/src/core/entities/DriveFileEntityService.ts index 5148b2ca9e..14be000367 100644 --- a/packages/backend/src/core/entities/DriveFileEntityService.ts +++ b/packages/backend/src/core/entities/DriveFileEntityService.ts @@ -90,7 +90,7 @@ export class DriveFileEntityService { if (file.type.startsWith('video')) { if (file.thumbnailUrl) return file.thumbnailUrl; - return this.videoProcessingService.getExternalVideoThumbnailUrl(file.webpublicUrl ?? file.url ?? file.uri); + return this.videoProcessingService.getExternalVideoThumbnailUrl(file.webpublicUrl ?? file.url); } else if (file.uri != null && file.userHost != null && this.config.externalMediaProxyEnabled) { // 動画ではなくリモートかつメディアプロキシ return this.getProxiedUrl(file.uri, 'static'); @@ -145,7 +145,7 @@ export class DriveFileEntityService { .select('SUM(file.size)', 'sum') .getRawOne(); - return parseInt(sum, 10) ?? 0; + return parseInt(sum, 10) || 0; } @bindThis @@ -157,7 +157,7 @@ export class DriveFileEntityService { .select('SUM(file.size)', 'sum') .getRawOne(); - return parseInt(sum, 10) ?? 0; + return parseInt(sum, 10) || 0; } @bindThis @@ -169,7 +169,7 @@ export class DriveFileEntityService { .select('SUM(file.size)', 'sum') .getRawOne(); - return parseInt(sum, 10) ?? 0; + return parseInt(sum, 10) || 0; } @bindThis @@ -181,7 +181,7 @@ export class DriveFileEntityService { .select('SUM(file.size)', 'sum') .getRawOne(); - return parseInt(sum, 10) ?? 0; + return parseInt(sum, 10) || 0; } @bindThis diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 674594296c..7cb7e4b913 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -318,7 +318,7 @@ export class NoteEntityService implements OnModuleInit { text: text, cw: note.cw, visibility: note.visibility, - localOnly: note.localOnly ?? undefined, + localOnly: note.localOnly, reactionAcceptance: note.reactionAcceptance, visibleUserIds: note.visibility === 'specified' ? note.visibleUserIds : undefined, renoteCount: note.renoteCount, diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 212994feef..4a3ca00849 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -333,8 +333,8 @@ export class UserEntityService implements OnModuleInit { host: user.host, avatarUrl: user.avatarUrl ?? this.getIdenticonUrl(user), avatarBlurhash: user.avatarBlurhash, - isBot: user.isBot ?? falsy, - isCat: user.isCat ?? falsy, + isBot: user.isBot, + isCat: user.isCat, instance: user.host ? this.federatedInstanceService.federatedInstanceCache.fetch(user.host).then(instance => instance ? { name: instance.name, softwareName: instance.softwareName, @@ -367,7 +367,7 @@ export class UserEntityService implements OnModuleInit { bannerBlurhash: user.bannerBlurhash, isLocked: user.isLocked, isSilenced: this.roleService.getUserPolicies(user.id).then(r => !r.canPublicNote), - isSuspended: user.isSuspended ?? falsy, + isSuspended: user.isSuspended, description: profile!.description, location: profile!.location, birthday: profile!.birthday, diff --git a/packages/backend/src/daemons/ServerStatsService.ts b/packages/backend/src/daemons/ServerStatsService.ts index d294628740..c5ef9b2fa3 100644 --- a/packages/backend/src/daemons/ServerStatsService.ts +++ b/packages/backend/src/daemons/ServerStatsService.ts @@ -108,6 +108,5 @@ async function net() { // FS STAT async function fs() { - const data = await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 })); - return data ?? { rIO_sec: 0, wIO_sec: 0 }; + return await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 })); } diff --git a/packages/backend/src/queue/processors/InboxProcessorService.ts b/packages/backend/src/queue/processors/InboxProcessorService.ts index 99e823f9fa..89d4ea503e 100644 --- a/packages/backend/src/queue/processors/InboxProcessorService.ts +++ b/packages/backend/src/queue/processors/InboxProcessorService.ts @@ -88,7 +88,7 @@ export class InboxProcessorService { if (err.isClientError) { throw new Bull.UnrecoverableError(`skip: Ignored deleted actors on both ends ${activity.actor} - ${err.statusCode}`); } - throw new Error(`Error in actor ${activity.actor} - ${err.statusCode ?? err}`); + throw new Error(`Error in actor ${activity.actor} - ${err.statusCode}`); } } } diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index de755cccb9..3ccf4af66d 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -49,7 +49,7 @@ class HomeTimelineChannel extends Channel { } // Ignore notes from instances the user has muted - if (isInstanceMuted(note, new Set(this.userProfile!.mutedInstances ?? []))) return; + if (isInstanceMuted(note, new Set(this.userProfile!.mutedInstances))) return; if (note.visibility === 'followers') { if (!Object.hasOwn(this.following, note.userId)) return; diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 83f0bccd90..760fab60a4 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -69,7 +69,7 @@ class HybridTimelineChannel extends Channel { } // Ignore notes from instances the user has muted - if (isInstanceMuted(note, new Set(this.userProfile!.mutedInstances ?? []))) return; + if (isInstanceMuted(note, new Set(this.userProfile!.mutedInstances))) return; // 関係ない返信は除外 if (note.reply && !this.following[note.userId]?.withReplies && !this.withReplies) { diff --git a/packages/backend/src/server/web/FeedService.ts b/packages/backend/src/server/web/FeedService.ts index b547630298..3ba26ad34a 100644 --- a/packages/backend/src/server/web/FeedService.ts +++ b/packages/backend/src/server/web/FeedService.ts @@ -83,7 +83,7 @@ export class FeedService { date: this.idService.parse(note.id).date, description: note.cw ?? undefined, content: note.text ?? undefined, - image: file ? this.driveFileEntityService.getPublicUrl(file) ?? undefined : undefined, + image: file ? this.driveFileEntityService.getPublicUrl(file) : undefined, }); }