Skip to content

Commit

Permalink
✨ When multiple tags are ex/included, use OR operator instead of AND (#…
Browse files Browse the repository at this point in the history
…2386)

* ✨ When multiple tags are ex/included, use OR operator instead of AND

* 🧹 Remove unnecessary casting
  • Loading branch information
foysalit authored Apr 15, 2024
1 parent 0f915a6 commit d4d5a6e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/ozone/src/mod-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,17 +759,19 @@ 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[]`,
)
}

if (excludeTags.length) {
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),
)
Expand All @@ -787,7 +789,6 @@ export class ModerationService {
tryIndex: true,
nullsLast: true,
})

const results = await paginatedBuilder.execute()

const infos = await this.views.getAccoutInfosByDid(
Expand Down
27 changes: 27 additions & 0 deletions packages/ozone/tests/moderation-statuses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit d4d5a6e

Please sign in to comment.