Actions Taking Longer than Expected Despite Logic for Exiting Early
Last Updated:
Overview
Cause
The following example code would always spend some time loading the axios library despite it not being called for a user who had a certain metadata flag:
const axios = require('axios')
exports.onExecutePostLogin = async (event, api) => {
//check if user has a flag that indicates axios call is not required
const metadataFlag = event.user.app_metadata.myCustomFlag
if (metadataFlag) {
// exit early
return
}
// perform axios call...
}Solution
The impact of the axios library is relatively small and only given for demonstration purposes, but other, larger libraries may have bigger impacts on runtimes.
For more performance tips, see Performance Best Practices.