mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: filtering logic of flags [breaking]
When combining filters, the old logic assumed that every filter was exclusive, unless that filter contained multiple items, in which case it was added to a list of "or" filters that returned all matching flags. A fault was discovered in that if you passed in multiple "or" states, it did not return flags with the expected filtering. e.g. open flags, closed flags, flags of cid 1, flags of cid 2 This could return open flags of cid 3, since all of the filters were "OR"'d. This logic change updates the behaviour so disparate OR sets are intersected (ANDed).
This commit is contained in:
@@ -39,7 +39,7 @@ Flags.init = async function () {
|
||||
if (value.length === 1) {
|
||||
sets.push(prefix + value[0]);
|
||||
} else {
|
||||
value.forEach(x => orSets.push(prefix + x));
|
||||
orSets.push(value.map(x => prefix + x));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,12 @@ Flags.getFlagIdsWithFilters = async function ({ filters, uid }) {
|
||||
}
|
||||
|
||||
if (orSets.length) {
|
||||
const _flagIds = await db.getSortedSetRevUnion({ sets: orSets, start: 0, stop: -1, aggregate: 'MAX' });
|
||||
let _flagIds = await Promise.all(orSets.map(async orSet => await db.getSortedSetRevUnion({ sets: orSet, start: 0, stop: -1, aggregate: 'MAX' })));
|
||||
|
||||
// Each individual orSet is ANDed together to construct the final list of flagIds
|
||||
_flagIds = _.intersection(..._flagIds);
|
||||
|
||||
// Merge with flagIds returned by sets
|
||||
if (sets.length) {
|
||||
// If flag ids are already present, return a subset of flags that are in both sets
|
||||
flagIds = _.intersection(flagIds, _flagIds);
|
||||
|
||||
Reference in New Issue
Block a user