Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5375,6 +5375,22 @@ describe('Parse.Query testing', () => {
expect(result.executionStats).not.toBeUndefined();
});

it_only_db('mongo')('does not run afterFind on explain results', async () => {
let afterFindCalled = false;
Parse.Cloud.afterFind('AfterFindExplain', () => {
afterFindCalled = true;
return []; // empty return would drop the explain plan if the trigger ran
});
const obj = new Parse.Object('AfterFindExplain');
await obj.save();
const query = new Parse.Query('AfterFindExplain');
query.equalTo('objectId', obj.id);
query.explain();
const result = await query.find({ useMasterKey: true });
expect(result.executionStats).not.toBeUndefined(); // plan passed through untouched
expect(afterFindCalled).toBe(false); // afterFind skipped for explain
});

it('should query with distinct within eachBatch and direct access enabled', async () => {
await reconfigureServer({
directAccess: true,
Expand Down
4 changes: 2 additions & 2 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,8 @@ _UnsafeRestQuery.prototype.runAfterFindTrigger = function () {
if (!hasAfterFindHook) {
return Promise.resolve();
}
// Skip Aggregate and Distinct Queries
if (this.findOptions.pipeline || this.findOptions.distinct) {
// Skip Aggregate, Distinct and Explain Queries
if (this.findOptions.pipeline || this.findOptions.distinct || this.findOptions.explain) {
return Promise.resolve();
}

Expand Down
Loading