I am experiencing multiple afterDelete
entries logged for User and Profile classes triggered by one action, in this example when deleting an account:
2021-06-10T11:40:44.221Z - afterDelete triggered for PrsProfile for user undefined:
Input: {…}
Result: {}
2021-06-10T11:40:44.064Z - afterDelete triggered for PrsProfile for user undefined:
Input: {…}
2021-06-10T11:40:44.012Z - afterDelete triggered for _User for user vcY6Y9e0CW:
Input: {… (truncated)
2021-06-10T11:40:44.012Z - afterDelete triggered for _User for user vcY6Y9e0CW:
Input: {… (truncated)
Result: {}
The related cloud functions are:
User object - deleting all sessions and users Profile object
Parse.Cloud.afterDelete(Parse.User, ({object, log}) => {
const query = new Parse.Query(Parse.Session);
query.equalTo("user", object);
query.find({useMasterKey: true}).then((sessions) => {
Parse.Object.destroyAll(sessions, {useMasterKey: true});
}).catch((error) => {
log.info(`Error finding related session ${error.code}: ${error.message}`);
});
const profileQuery = new Parse.Query("PrsProfile");
profileQuery.equalTo("objectId", object.id);
profileQuery.find({useMasterKey: true}).then((profiles) => {
Parse.Object.destroyAll(profiles, {useMasterKey: true});
}).catch((error) => {
log.info(`Error finding related profile ${error.code}: ${error.message}`);
});
return;
});
Profile object - deleting file objects and related files in storage and deleting index in ElasticSearch
Parse.Cloud.afterDelete("PrsProfile", async ( {object, log}) => {
const filesQuery = new Parse.Query("FileObj");
filesQuery.equalTo("ow", object.id);
filesQuery.find({useMasterKey: true}).then((fileObjects) => {
Parse.Object.destroyAll(fileObjects, {useMasterKey: true});
}).catch((error) => {
log.info(`Error removing file objects: ${error.code}: ${error.message}`);
});
try {
await elastic.deleteIndexProfile(object);
} catch (e) {
log.error(`error deleting profile in elasticSearch ${e}`);
}
return;
});
ElasticSearch delete index
deleteIndexProfile = async function(profile) {
const { body } = await esClient.delete({
id: profile.id,
index: "profile"
})
return body;
}
Is it wrong to call multiple functions from one trigger or is just my syntax wrong?
What I found also strange is that I get a log beforeSave when user logs (even the client is not calling any save), is that normal behaviour?
2021-06-10T11:36:57.026Z - beforeSave triggered for _User for user undefined:
Input: {“email”:“[email protected]”,“username”:“[email protected]”,“password”:“**”,“ACL”:{}}
Result: {“object”:{“ACL”:{},“email”:“[email protected]”,“username”:“[email protected]”,“password”:“*”}}