Description
Issue Description
I am currently using Parse Server 3.6.0. Last week I attempted to migrate to the latest version of Parse Server and I had to revert back due to performance issues related to specific queries. I think I know how to solve the performance issues, however, I found an interesting behavior during my investigation.
It seems that in the new version of Parse Server, whenever I query a table which has a CLP entry that gives access to the user in a specific column of the table, the resultant mongodb query ends up as an $or
query. Also, one of the branches in the $or query has a clause to match the user pointer object (which seems useless because pointers are not stored that way in the mongodb table).
Steps to reproduce
I am close to a 100% sure (but not 100% sure) that the following steps reproduce the problem.
-
Create a class
FooClass
with two columns:name | String
anduser | Pointer<User>
. -
Add a CLP giving read/write access to the
user
column.
- Run the following Parse query in
explain
mode and look at the mongodb query. In my environment, I reproduced it using a user session token. Not sure if it can be reproduced with a master key.
const query = await new Parse.Query('FooClass')
.explain(true)
.equalTo('name', 'some-name')
.find({sessionToken: token});
Expected Results
A simpler mongodb query
Actual Outcome
"parsedQuery": {
"$and": [
{
"$or": [
{
"$and": [
{
"_p_user": {
"$eq": "_User$5YImRRMWLs"
}
},
{
"name": {
"$eq": "some-name"
}
}
]
},
{
"$and": [
{
"_p_user": {
"$eq": {
"__type": "Pointer",
"className": "_User",
"objectId": "5YImRRMWLs"
}
}
},
{
"name": {
"$eq": "some-name"
}
}
]
}
]
},
{
"_rperm": {
"$in": [
null,
"*",
"5YImRRMWLs",
"role:role1"
]
}
}
]
},
Environment Setup
-
Server
- parse-server version (Be specific! Don't say 'latest'.) : [4.2.0] (In 3.6.0 the problem does not happen)
- Operating System: [Linux]
- Hardware: [AWS EC2]
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): [AWS]
-
Database
- MongoDB version: [3.6.9] (But I have reproduced it with 4.2 as well)
- Storage engine: [WiredTiger]
- Hardware: [EC2]
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): [AWS]