server: remove SQL boolean comparisons

This commit is contained in:
Johann150 2023-01-09 20:43:12 +01:00
parent 4fe288f17c
commit fdf30f60e6
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
14 changed files with 34 additions and 34 deletions

View file

@ -57,7 +57,7 @@ export default async (ctx: Router.RouterContext) => {
.where('note.visibility = \'public\'') .where('note.visibility = \'public\'')
.orWhere('note.visibility = \'home\''); .orWhere('note.visibility = \'home\'');
})) }))
.andWhere('note.localOnly = FALSE'); .andWhere('NOT note.localOnly');
const notes = await query.take(limit).getMany(); const notes = await query.take(limit).getMany();

View file

@ -93,8 +93,8 @@ export default define(meta, paramDef, async (ps) => {
const query = makePaginationQuery(AbuseUserReports.createQueryBuilder('report'), ps.sinceId, ps.untilId); const query = makePaginationQuery(AbuseUserReports.createQueryBuilder('report'), ps.sinceId, ps.untilId);
switch (ps.state) { switch (ps.state) {
case 'resolved': query.andWhere('report.resolved = TRUE'); break; case 'resolved': query.andWhere('report.resolved'); break;
case 'unresolved': query.andWhere('report.resolved = FALSE'); break; case 'unresolved': query.andWhere('NOT report.resolved'); break;
} }
switch (ps.reporterOrigin) { switch (ps.reporterOrigin) {

View file

@ -41,13 +41,13 @@ export default define(meta, paramDef, async (ps, me) => {
const query = Users.createQueryBuilder('user'); const query = Users.createQueryBuilder('user');
switch (ps.state) { switch (ps.state) {
case 'available': query.where('user.isSuspended = FALSE'); break; case 'available': query.where('NOT user.isSuspended'); break;
case 'admin': query.where('user.isAdmin = TRUE'); break; case 'admin': query.where('user.isAdmin'); break;
case 'moderator': query.where('user.isModerator = TRUE'); break; case 'moderator': query.where('user.isModerator'); break;
case 'adminOrModerator': query.where('user.isAdmin = TRUE OR user.isModerator = TRUE'); break; case 'adminOrModerator': query.where('user.isAdmin OR user.isModerator'); break;
case 'alive': query.where('user.updatedAt > :date', { date: new Date(Date.now() - 5 * DAY) }); break; case 'alive': query.where('user.updatedAt > :date', { date: new Date(Date.now() - 5 * DAY) }); break;
case 'silenced': query.where('user.isSilenced = TRUE'); break; case 'silenced': query.where('user.isSilenced'); break;
case 'suspended': query.where('user.isSuspended = TRUE'); break; case 'suspended': query.where('user.isSuspended'); break;
} }
switch (ps.origin) { switch (ps.origin) {

View file

@ -69,17 +69,17 @@ export default define(meta, paramDef, async (ps) => {
if (typeof ps.notResponding === 'boolean') { if (typeof ps.notResponding === 'boolean') {
if (ps.notResponding) { if (ps.notResponding) {
query.andWhere('instance.isNotResponding = TRUE'); query.andWhere('instance.isNotResponding');
} else { } else {
query.andWhere('instance.isNotResponding = FALSE'); query.andWhere('NOT instance.isNotResponding');
} }
} }
if (typeof ps.suspended === 'boolean') { if (typeof ps.suspended === 'boolean') {
if (ps.suspended) { if (ps.suspended) {
query.andWhere('instance.isSuspended = TRUE'); query.andWhere('instance.isSuspended');
} else { } else {
query.andWhere('instance.isSuspended = FALSE'); query.andWhere('NOT instance.isSuspended');
} }
} }

View file

@ -72,7 +72,7 @@ export default define(meta, paramDef, async (ps, user) => {
const suspendedQuery = Users.createQueryBuilder('users') const suspendedQuery = Users.createQueryBuilder('users')
.select('users.id') .select('users.id')
.where('users.isSuspended = TRUE'); .where('users.isSuspended');
const query = makePaginationQuery(Notifications.createQueryBuilder('notification'), ps.sinceId, ps.untilId) const query = makePaginationQuery(Notifications.createQueryBuilder('notification'), ps.sinceId, ps.untilId)
.andWhere('notification.notifieeId = :meId', { meId: user.id }) .andWhere('notification.notifieeId = :meId', { meId: user.id })

View file

@ -35,7 +35,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps) => { export default define(meta, paramDef, async (ps) => {
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId) const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
.andWhere('note.visibility = \'public\'') .andWhere('note.visibility = \'public\'')
.andWhere('note.localOnly = FALSE') .andWhere('NOT note.localOnly')
.innerJoinAndSelect('note.user', 'user') .innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('user.avatar', 'avatar') .leftJoinAndSelect('user.avatar', 'avatar')
.leftJoinAndSelect('user.banner', 'banner') .leftJoinAndSelect('user.banner', 'banner')
@ -65,7 +65,7 @@ export default define(meta, paramDef, async (ps) => {
} }
if (ps.poll !== undefined) { if (ps.poll !== undefined) {
query.andWhere(ps.poll ? 'note.hasPoll = TRUE' : 'note.hasPoll = FALSE'); query.andWhere((ps.poll ? '' : 'NOT') + 'note.hasPoll');
} }
// TODO // TODO

View file

@ -98,7 +98,7 @@ export default define(meta, paramDef, async (ps, user) => {
if (ps.excludeNsfw) { if (ps.excludeNsfw) {
query.andWhere('note.cw IS NULL'); query.andWhere('note.cw IS NULL');
query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive" = TRUE)'); query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive")');
} }
} }
//#endregion //#endregion

View file

@ -127,9 +127,9 @@ export default define(meta, paramDef, async (ps, me) => {
if (ps.poll != null) { if (ps.poll != null) {
if (ps.poll) { if (ps.poll) {
query.andWhere('note.hasPoll = TRUE'); query.andWhere('note.hasPoll');
} else { } else {
query.andWhere('note.hasPoll = FALSE'); query.andWhere('NOT note.hasPoll');
} }
} }

View file

@ -41,12 +41,12 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => { export default define(meta, paramDef, async (ps, me) => {
const query = Users.createQueryBuilder('user'); const query = Users.createQueryBuilder('user');
query.where('user.isExplorable = TRUE'); query.where('user.isExplorable');
switch (ps.state) { switch (ps.state) {
case 'admin': query.andWhere('user.isAdmin = TRUE'); break; case 'admin': query.andWhere('user.isAdmin'); break;
case 'moderator': query.andWhere('user.isModerator = TRUE'); break; case 'moderator': query.andWhere('user.isModerator'); break;
case 'adminOrModerator': query.andWhere('user.isAdmin = TRUE OR user.isModerator = TRUE'); break; case 'adminOrModerator': query.andWhere('user.isAdmin OR user.isModerator'); break;
case 'alive': query.andWhere('user.updatedAt > :date', { date: new Date(Date.now() - 5 * DAY) }); break; case 'alive': query.andWhere('user.updatedAt > :date', { date: new Date(Date.now() - 5 * DAY) }); break;
} }

View file

@ -90,7 +90,7 @@ export default define(meta, paramDef, async (ps, me) => {
if (ps.excludeNsfw) { if (ps.excludeNsfw) {
query.andWhere('note.cw IS NULL'); query.andWhere('note.cw IS NULL');
query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive" = TRUE)'); query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive")');
} }
} }

View file

@ -36,8 +36,8 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => { export default define(meta, paramDef, async (ps, me) => {
const query = Users.createQueryBuilder('user') const query = Users.createQueryBuilder('user')
.where('user.isLocked = FALSE') .where('NOT user.isLocked')
.andWhere('user.isExplorable = TRUE') .andWhere('user.isExplorable')
.andWhere('user.host IS NULL') .andWhere('user.host IS NULL')
.andWhere('user.updatedAt >= :date', { date: new Date(Date.now() - (7 * DAY)) }) .andWhere('user.updatedAt >= :date', { date: new Date(Date.now() - (7 * DAY)) })
.andWhere('user.id != :meId', { meId: me.id }) .andWhere('user.id != :meId', { meId: me.id })

View file

@ -44,7 +44,7 @@ export default define(meta, paramDef, async (ps, me) => {
if (ps.host) { if (ps.host) {
const q = Users.createQueryBuilder('user') const q = Users.createQueryBuilder('user')
.where('user.isSuspended = FALSE') .where('NOT user.isSuspended')
.andWhere('user.host LIKE :host', { host: ps.host.toLowerCase() + '%' }); .andWhere('user.host LIKE :host', { host: ps.host.toLowerCase() + '%' });
if (ps.username) { if (ps.username) {
@ -68,7 +68,7 @@ export default define(meta, paramDef, async (ps, me) => {
const query = Users.createQueryBuilder('user') const query = Users.createQueryBuilder('user')
.where(`user.id IN (${ followingQuery.getQuery() })`) .where(`user.id IN (${ followingQuery.getQuery() })`)
.andWhere('user.id != :meId', { meId: me.id }) .andWhere('user.id != :meId', { meId: me.id })
.andWhere('user.isSuspended = FALSE') .andWhere('NOT user.isSuspended')
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' }) .andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
.andWhere(new Brackets(qb => { qb .andWhere(new Brackets(qb => { qb
.where('user.updatedAt IS NULL') .where('user.updatedAt IS NULL')
@ -86,7 +86,7 @@ export default define(meta, paramDef, async (ps, me) => {
const otherQuery = await Users.createQueryBuilder('user') const otherQuery = await Users.createQueryBuilder('user')
.where(`user.id NOT IN (${ followingQuery.getQuery() })`) .where(`user.id NOT IN (${ followingQuery.getQuery() })`)
.andWhere('user.id != :meId', { meId: me.id }) .andWhere('user.id != :meId', { meId: me.id })
.andWhere('user.isSuspended = FALSE') .andWhere('user.isSuspended')
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' }) .andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
.andWhere('user.updatedAt IS NOT NULL'); .andWhere('user.updatedAt IS NOT NULL');
@ -101,7 +101,7 @@ export default define(meta, paramDef, async (ps, me) => {
} }
} else { } else {
users = await Users.createQueryBuilder('user') users = await Users.createQueryBuilder('user')
.where('user.isSuspended = FALSE') .where('user.isSuspended')
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' }) .andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
.andWhere('user.updatedAt IS NOT NULL') .andWhere('user.updatedAt IS NOT NULL')
.orderBy('user.updatedAt', 'DESC') .orderBy('user.updatedAt', 'DESC')

View file

@ -49,7 +49,7 @@ export default define(meta, paramDef, async (ps, me) => {
.where('user.updatedAt IS NULL') .where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold }); .orWhere('user.updatedAt > :activeThreshold', { activeThreshold });
})) }))
.andWhere('user.isSuspended = FALSE'); .andWhere('NOT user.isSuspended');
if (ps.origin === 'local') { if (ps.origin === 'local') {
usernameQuery.andWhere('user.host IS NULL'); usernameQuery.andWhere('user.host IS NULL');
@ -76,7 +76,7 @@ export default define(meta, paramDef, async (ps, me) => {
.where('user.updatedAt IS NULL') .where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold }); .orWhere('user.updatedAt > :activeThreshold', { activeThreshold });
})) }))
.andWhere('user.isSuspended = FALSE'); .andWhere('NOT user.isSuspended');
if (ps.origin === 'local') { if (ps.origin === 'local') {
nameQuery.andWhere('user.host IS NULL'); nameQuery.andWhere('user.host IS NULL');
@ -109,7 +109,7 @@ export default define(meta, paramDef, async (ps, me) => {
.where('user.updatedAt IS NULL') .where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold }); .orWhere('user.updatedAt > :activeThreshold', { activeThreshold });
})) }))
.andWhere('user.isSuspended = FALSE') .andWhere('NOT user.isSuspended')
.setParameters(profQuery.getParameters()); .setParameters(profQuery.getParameters());
users = users.concat(await query users = users.concat(await query

View file

@ -293,7 +293,7 @@ async function upload(key: string, stream: fs.ReadStream | Buffer, _type: string
async function deleteOldFile(user: IRemoteUser): Promise<void> { async function deleteOldFile(user: IRemoteUser): Promise<void> {
const q = DriveFiles.createQueryBuilder('file') const q = DriveFiles.createQueryBuilder('file')
.where('file.userId = :userId', { userId: user.id }) .where('file.userId = :userId', { userId: user.id })
.andWhere('file.isLink = FALSE'); .andWhere('NOT file.isLink');
if (user.avatarId) { if (user.avatarId) {
q.andWhere('file.id != :avatarId', { avatarId: user.avatarId }); q.andWhere('file.id != :avatarId', { avatarId: user.avatarId });