MongoDB $or Queries avoid SERVER-13732 bug (#3476)
MongoDB has an unfixed bug in all supported versions 2.6-3.4 which results in suboptimal index usage for `$or` queries when the query has implicit `$and`s at the query root. When adding `_rperm` to `$or` queries, Parse accidentally creates queries which hit this bug. The fix in this commit applies the suggested workaround of putting the `_rperm` property inside all `$or` subdocuments, moving it from the top level and leaving `$or` as the only top-level operator. MongoDB Bug Link: https://jira.mongodb.org/browse/SERVER-13732
This commit is contained in:
committed by
Tyler Brock
parent
66cdfaed4b
commit
96a9588a6e
@@ -18,7 +18,14 @@ function addWriteACL(query, acl) {
|
|||||||
function addReadACL(query, acl) {
|
function addReadACL(query, acl) {
|
||||||
const newQuery = _.cloneDeep(query);
|
const newQuery = _.cloneDeep(query);
|
||||||
//Can't be any existing '_rperm' query, we don't allow client queries on that, no need to $and
|
//Can't be any existing '_rperm' query, we don't allow client queries on that, no need to $and
|
||||||
newQuery._rperm = { "$in" : [null, "*", ...acl]};
|
if (newQuery.hasOwnProperty('$or')) {
|
||||||
|
newQuery.$or = newQuery.$or.map(function(qobj) {
|
||||||
|
qobj._rperm = {'$in' : [null, '*', ...acl]};
|
||||||
|
return qobj;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
newQuery._rperm = { "$in" : [null, "*", ...acl]};
|
||||||
|
}
|
||||||
return newQuery;
|
return newQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user