server: remove SQL boolean comparisons
All checks were successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
Johann150 2023-01-09 20:43:12 +01:00
parent 4fe288f17c
commit fdf30f60e6
Signed by: 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\'')
.orWhere('note.visibility = \'home\'');
}))
.andWhere('note.localOnly = FALSE');
.andWhere('NOT note.localOnly');
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);
switch (ps.state) {
case 'resolved': query.andWhere('report.resolved = TRUE'); break;
case 'unresolved': query.andWhere('report.resolved = FALSE'); break;
case 'resolved': query.andWhere('report.resolved'); break;
case 'unresolved': query.andWhere('NOT report.resolved'); break;
}
switch (ps.reporterOrigin) {

View file

@ -41,13 +41,13 @@ export default define(meta, paramDef, async (ps, me) => {
const query = Users.createQueryBuilder('user');
switch (ps.state) {
case 'available': query.where('user.isSuspended = FALSE'); break;
case 'admin': query.where('user.isAdmin = TRUE'); break;
case 'moderator': query.where('user.isModerator = TRUE'); break;
case 'adminOrModerator': query.where('user.isAdmin = TRUE OR user.isModerator = TRUE'); break;
case 'available': query.where('NOT user.isSuspended'); break;
case 'admin': query.where('user.isAdmin'); break;
case 'moderator': query.where('user.isModerator'); 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 'silenced': query.where('user.isSilenced = TRUE'); break;
case 'suspended': query.where('user.isSuspended = TRUE'); break;
case 'silenced': query.where('user.isSilenced'); break;
case 'suspended': query.where('user.isSuspended'); break;
}
switch (ps.origin) {

View file

@ -69,17 +69,17 @@ export default define(meta, paramDef, async (ps) => {
if (typeof ps.notResponding === 'boolean') {
if (ps.notResponding) {
query.andWhere('instance.isNotResponding = TRUE');
query.andWhere('instance.isNotResponding');
} else {
query.andWhere('instance.isNotResponding = FALSE');
query.andWhere('NOT instance.isNotResponding');
}
}
if (typeof ps.suspended === 'boolean') {
if (ps.suspended) {
query.andWhere('instance.isSuspended = TRUE');
query.andWhere('instance.isSuspended');
} 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')
.select('users.id')
.where('users.isSuspended = TRUE');
.where('users.isSuspended');
const query = makePaginationQuery(Notifications.createQueryBuilder('notification'), ps.sinceId, ps.untilId)
.andWhere('notification.notifieeId = :meId', { meId: user.id })

View file

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

View file

@ -98,7 +98,7 @@ export default define(meta, paramDef, async (ps, user) => {
if (ps.excludeNsfw) {
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

View file

@ -127,9 +127,9 @@ export default define(meta, paramDef, async (ps, me) => {
if (ps.poll != null) {
if (ps.poll) {
query.andWhere('note.hasPoll = TRUE');
query.andWhere('note.hasPoll');
} 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
export default define(meta, paramDef, async (ps, me) => {
const query = Users.createQueryBuilder('user');
query.where('user.isExplorable = TRUE');
query.where('user.isExplorable');
switch (ps.state) {
case 'admin': query.andWhere('user.isAdmin = TRUE'); break;
case 'moderator': query.andWhere('user.isModerator = TRUE'); break;
case 'adminOrModerator': query.andWhere('user.isAdmin = TRUE OR user.isModerator = TRUE'); break;
case 'admin': query.andWhere('user.isAdmin'); break;
case 'moderator': query.andWhere('user.isModerator'); 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;
}

View file

@ -90,7 +90,7 @@ export default define(meta, paramDef, async (ps, me) => {
if (ps.excludeNsfw) {
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
export default define(meta, paramDef, async (ps, me) => {
const query = Users.createQueryBuilder('user')
.where('user.isLocked = FALSE')
.andWhere('user.isExplorable = TRUE')
.where('NOT user.isLocked')
.andWhere('user.isExplorable')
.andWhere('user.host IS NULL')
.andWhere('user.updatedAt >= :date', { date: new Date(Date.now() - (7 * DAY)) })
.andWhere('user.id != :meId', { meId: me.id })

View file

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

View file

@ -49,7 +49,7 @@ export default define(meta, paramDef, async (ps, me) => {
.where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold });
}))
.andWhere('user.isSuspended = FALSE');
.andWhere('NOT user.isSuspended');
if (ps.origin === 'local') {
usernameQuery.andWhere('user.host IS NULL');
@ -76,7 +76,7 @@ export default define(meta, paramDef, async (ps, me) => {
.where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold });
}))
.andWhere('user.isSuspended = FALSE');
.andWhere('NOT user.isSuspended');
if (ps.origin === 'local') {
nameQuery.andWhere('user.host IS NULL');
@ -109,7 +109,7 @@ export default define(meta, paramDef, async (ps, me) => {
.where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold });
}))
.andWhere('user.isSuspended = FALSE')
.andWhere('NOT user.isSuspended')
.setParameters(profQuery.getParameters());
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> {
const q = DriveFiles.createQueryBuilder('file')
.where('file.userId = :userId', { userId: user.id })
.andWhere('file.isLink = FALSE');
.andWhere('NOT file.isLink');
if (user.avatarId) {
q.andWhere('file.id != :avatarId', { avatarId: user.avatarId });