Hi,
I would like to investigate query performance and was able to set a simple function that returns array of objects.
Parse.Cloud.define("newProfiles", async (request) => {
const basicQuery = new Parse.Query("PrsProfile");
basicQuery.lessThanOrEqualTo("ag", 26);
basicQuery.greaterThanOrEqualTo("ag", 23);
const results = await basicQuery.find({ sessionToken: request.user.getSessionToken() });
return results;
});
This works as intended and I have PrsProfile object already as a struct, so decoding is not an issue. But when I chain basicQuery.explain()
in to the function, it returns result that I canât read well:
error: The data couldnât be read because it isnât in the correct format. Format: Optional("{\"result\":{\"queryPlanner\":{\"mongosPlannerVersion\":1,\"winningPlan\":{\"stage\":\"SINGLE_SHARD\",\"shards\":[{\"shardName\":\"rs6\",\"connectionString\":\"rs6/MongoRS601A.back4app.com:27018,MongoRS602A.back4app.com:27018\",\"serverInfo\":{\"host\":\"MongoRS601A.back4app.com\",\"port\":27018,\"version\":\"3.6.8-2.0\",\"gitVersion\":\"1fb3fbd45602ef799b4053edbe1f2748ab97eebe\"},\"plannerVersion\":1,\"namespace\":\"a1b5c903c7814f7a836a269dc63ff84f.PrsProfile\",\"indexFilterSet\":false,\"parsedQuery\":{\"$and\":[{\"ag\":{\"$lte\":26}},{\"ag\":{\"$gte\":23}},{\"_rperm\":{\"$in\":[null,\"\",\"zyLHKLV5Ll\"]}}]},\"winningPlan\":{\"stage\":\"LIMIT\",\"limitAmount\":100,\"inputStage\":{\"stage\":\"COLLSCAN\",\"filter\":{\"$and\":[{\"ag\":{\"$lte\":26}},{\"ag\":{\"$gte\":23}},{\"_rperm\":{\"$in\":[null,\"\",\"zyLHKLV5Ll\"]}}]},\"direction\":\"forward\"}},\"rejectedPlans\":}]}},\"executionStats\":{\"nReturned\":1,\"executionTimeMillis\":3,\"totalKeysExamined\":0,\"totalDocsExamined\":1,\"executionStages\":{\"stage\":\"SINGLE_SHARD\",\"nReturned\":1,\"executionTimeMillis\":3,\"totalKeysExamined\":0,\"totalDocsExamined\":1,\"totalChildMillis\":0,\"shards\":[{\"shardName\":\"rs6\",\"executionSuccess\":true,\"executionStages\":{\"stage\":\"LIMIT\",\"nReturned\":1,\"executionTimeMillisEstimate\":0,\"works\":3,\"advanced\":1,\"needTime\":1,\"needYield\":0,\"saveState\":0,\"restoreState\":0,\"isEOF\":1,\"invalidates\":0,\"limitAmount\":100,\"inputStage\":{\"stage\":\"COLLSCAN\",\"filter\":{\"$and\":[{\"ag\":{\"$lte\":26}},{\"ag\":{\"$gte\":23}},{\"_rperm\":{\"$in\":[null,\"*\",\"zyLHKLV5Ll\"]}}]},\"nReturned\":1,\"executionTimeMillisEstimate\":0,\"works\":3,\"advanced\":1,\"needTime\":1,\"needYield\":0,\"saveState\":0,\"restoreState\":0,\"isEOF\":1,\"invalidates\":0,\"direction\":\"forward\",\"docsExamined\":1}}}]},\"allPlansExecution\":[{\"shardName\":\"rs6\",\"allPlans\":}]},\"ok\":1}}")")
I am using following definition with ParseSwift SDK:
let findQuery = Cloud(functionJobName: "newProfiles")
findQuery.runFunction { result in
switch result {
case .success(let results):
print("Response from cloud function: \(results))")
case .failure(let error):
print("Error calling cloud function: \(error)")
}
}
The typealias in the Cloud struct is for me the unknownâŚ
import** ParseSwift
//: Create your own value typed `ParseCloud` type.
struct** Cloud: ParseCloud {
//: Return type of your Cloud Function
typealias ReturnType = ????
//: These are required for Object
var functionJobName: String
}
Does anyone has a wrapper or useful trick, how to print explain() result in Xcode in a better way?
Thank you!