From d4d5a6edba972c0e9976289bde8bc0b42ff547ca Mon Sep 17 00:00:00 2001 From: Foysal Ahamed Date: Mon, 15 Apr 2024 17:15:21 +0200 Subject: [PATCH] :sparkles: When multiple tags are ex/included, use OR operator instead of AND (#2386) * :sparkles: When multiple tags are ex/included, use OR operator instead of AND * :broom: Remove unnecessary casting --- packages/ozone/src/mod-service/index.ts | 11 ++++---- .../ozone/tests/moderation-statuses.test.ts | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/packages/ozone/src/mod-service/index.ts b/packages/ozone/src/mod-service/index.ts index 2ce290cbbce..27fba00f5cb 100644 --- a/packages/ozone/src/mod-service/index.ts +++ b/packages/ozone/src/mod-service/index.ts @@ -759,7 +759,9 @@ export class ModerationService { if (tags.length) { builder = builder.where( - sql`${ref('moderation_subject_status.tags')} @> ${jsonb(tags)}`, + sql`${ref('moderation_subject_status.tags')} ?| array[${sql.join( + tags, + )}]::TEXT[]`, ) } @@ -767,9 +769,9 @@ export class ModerationService { builder = builder.where((qb) => qb .where( - sql`NOT(${ref('moderation_subject_status.tags')} @> ${jsonb( - excludeTags, - )})`, + sql`NOT(${ref( + 'moderation_subject_status.tags', + )} ?| array[${sql.join(excludeTags)}]::TEXT[])`, ) .orWhere('tags', 'is', null), ) @@ -787,7 +789,6 @@ export class ModerationService { tryIndex: true, nullsLast: true, }) - const results = await paginatedBuilder.execute() const infos = await this.views.getAccoutInfosByDid( diff --git a/packages/ozone/tests/moderation-statuses.test.ts b/packages/ozone/tests/moderation-statuses.test.ts index ddc1e32aec2..f85de7f2828 100644 --- a/packages/ozone/tests/moderation-statuses.test.ts +++ b/packages/ozone/tests/moderation-statuses.test.ts @@ -99,6 +99,33 @@ describe('moderation-statuses', () => { expect(nonKlingonQueue.subjectStatuses.map((s) => s.id)).not.toContain( klingonQueue.subjectStatuses[0].id, ) + + // Verify multi lang tag exclusion + Promise.all( + nonKlingonQueue.subjectStatuses.map((s, i) => { + return modClient.emitEvent({ + subject: s.subject, + event: { + $type: 'tools.ozone.moderation.defs#modEventTag', + add: [i % 2 ? 'lang:jp' : 'lang:it'], + remove: [], + comment: 'Adding custom lang tag', + }, + createdBy: sc.dids.alice, + }) + }), + ) + + const queueWithoutKlingonAndItalian = await modClient.queryStatuses({ + excludeTags: ['lang:i', 'lang:it'], + }) + + queueWithoutKlingonAndItalian.subjectStatuses + .map((s) => s.tags) + .flat() + .forEach((tag) => { + expect(['lang:it', 'lang:i']).not.toContain(tag) + }) }) it('returns paginated statuses', async () => {