refactor: use nullish coalescing / optional chaining

This seems to be more readable than ternary expressions.
This commit is contained in:
Johann150 2022-07-13 19:08:22 +02:00
parent 67450815cd
commit 0e3a9d1e0d
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
4 changed files with 10 additions and 11 deletions

View file

@ -195,7 +195,7 @@ export const db = new DataSource({
options: { options: {
host: config.redis.host, host: config.redis.host,
port: config.redis.port, port: config.redis.port,
family: config.redis.family == null ? 0 : config.redis.family, family: config.redis.family ?? 0,
password: config.redis.pass, password: config.redis.pass,
keyPrefix: `${config.redis.prefix}:query:`, keyPrefix: `${config.redis.prefix}:query:`,
db: config.redis.db || 0, db: config.redis.db || 0,

View file

@ -5,7 +5,7 @@ export function createConnection() {
return new Redis({ return new Redis({
port: config.redis.port, port: config.redis.port,
host: config.redis.host, host: config.redis.host,
family: config.redis.family == null ? 0 : config.redis.family, family: config.redis.family ?? 0,
password: config.redis.pass, password: config.redis.pass,
keyPrefix: `${config.redis.prefix}:`, keyPrefix: `${config.redis.prefix}:`,
db: config.redis.db || 0, db: config.redis.db || 0,

View file

@ -6,7 +6,7 @@ export function initialize<T>(name: string, limitPerSec = -1) {
redis: { redis: {
port: config.redis.port, port: config.redis.port,
host: config.redis.host, host: config.redis.host,
family: config.redis.family == null ? 0 : config.redis.family, family: config.redis.family ?? 0,
password: config.redis.pass, password: config.redis.pass,
db: config.redis.db || 0, db: config.redis.db || 0,
}, },

View file

@ -515,7 +515,7 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O
name: data.name, name: data.name,
text: data.text, text: data.text,
hasPoll: data.poll != null, hasPoll: data.poll != null,
cw: data.cw == null ? null : data.cw, cw: data.cw ?? null,
tags: tags.map(tag => normalizeForSearch(tag)), tags: tags.map(tag => normalizeForSearch(tag)),
emojis, emojis,
userId: user.id, userId: user.id,
@ -529,11 +529,11 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O
attachedFileTypes: data.files ? data.files.map(file => file.type) : [], attachedFileTypes: data.files ? data.files.map(file => file.type) : [],
// 以下非正規化データ // denormalized data below
replyUserId: data.reply ? data.reply.userId : null, replyUserId: data.reply?.userId,
replyUserHost: data.reply ? data.reply.userHost : null, replyUserHost: data.reply?.userHost,
renoteUserId: data.renote ? data.renote.userId : null, renoteUserId: data.renote?.userId,
renoteUserHost: data.renote ? data.renote.userHost : null, renoteUserHost: data.renote?.userHost,
userHost: user.host, userHost: user.host,
}); });
@ -546,10 +546,9 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O
const profiles = await UserProfiles.findBy({ userId: In(insert.mentions) }); const profiles = await UserProfiles.findBy({ userId: In(insert.mentions) });
insert.mentionedRemoteUsers = JSON.stringify(mentionedUsers.filter(u => Users.isRemoteUser(u)).map(u => { insert.mentionedRemoteUsers = JSON.stringify(mentionedUsers.filter(u => Users.isRemoteUser(u)).map(u => {
const profile = profiles.find(p => p.userId === u.id); const profile = profiles.find(p => p.userId === u.id);
const url = profile != null ? profile.url : null;
return { return {
uri: u.uri, uri: u.uri,
url: url == null ? undefined : url, url: profile?.url,
username: u.username, username: u.username,
host: u.host, host: u.host,
} as IMentionedRemoteUsers[0]; } as IMentionedRemoteUsers[0];