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: 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: {
host: config.redis.host,
port: config.redis.port,
family: config.redis.family == null ? 0 : config.redis.family,
family: config.redis.family ?? 0,
password: config.redis.pass,
keyPrefix: `${config.redis.prefix}:query:`,
db: config.redis.db || 0,

View file

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

View file

@ -6,7 +6,7 @@ export function initialize<T>(name: string, limitPerSec = -1) {
redis: {
port: config.redis.port,
host: config.redis.host,
family: config.redis.family == null ? 0 : config.redis.family,
family: config.redis.family ?? 0,
password: config.redis.pass,
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,
text: data.text,
hasPoll: data.poll != null,
cw: data.cw == null ? null : data.cw,
cw: data.cw ?? null,
tags: tags.map(tag => normalizeForSearch(tag)),
emojis,
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) : [],
// 以下非正規化データ
replyUserId: data.reply ? data.reply.userId : null,
replyUserHost: data.reply ? data.reply.userHost : null,
renoteUserId: data.renote ? data.renote.userId : null,
renoteUserHost: data.renote ? data.renote.userHost : null,
// denormalized data below
replyUserId: data.reply?.userId,
replyUserHost: data.reply?.userHost,
renoteUserId: data.renote?.userId,
renoteUserHost: data.renote?.userHost,
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) });
insert.mentionedRemoteUsers = JSON.stringify(mentionedUsers.filter(u => Users.isRemoteUser(u)).map(u => {
const profile = profiles.find(p => p.userId === u.id);
const url = profile != null ? profile.url : null;
return {
uri: u.uri,
url: url == null ? undefined : url,
url: profile?.url,
username: u.username,
host: u.host,
} as IMentionedRemoteUsers[0];