Skip to content

Commit

Permalink
#325: fix caching logic for automations together with verifications
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Aug 24, 2023
1 parent 4ea2779 commit 1099ed4
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class Automation extends MetadataType {
*/
static async retrieve(retrieveDir, _, __, key) {
let metadataMap;
if (!key && this._cachedMetadataMap) {
if (key && this._cachedMetadataMap?.[key]) {
metadataMap = {};
metadataMap[key] = this._cachedMetadataMap[key];
delete this._cachedMetadataMap;
} else if (!key && this._cachedMetadataMap) {
metadataMap = this._cachedMetadataMap;
delete this._cachedMetadataMap;
} else {
Expand Down Expand Up @@ -229,12 +233,18 @@ class Automation extends MetadataType {
* @returns {Promise.<TYPE.AutomationMapObj>} Promise of metadata
*/
static async retrieveForCache() {
// get automations for cache
const results = await this.client.soap.retrieveBulk('Program', [
'ObjectID',
'CustomerKey',
'Name',
]);
let results = {};
if (this._cachedMetadataMap) {
results.Results = Object.values(this._cachedMetadataMap);
delete this._cachedMetadataMap;
} else {
// get automations for cache
results = await this.client.soap.retrieveBulk('Program', [
'ObjectID',
'CustomerKey',
'Name',
]);
}
const resultsConverted = {};
if (Array.isArray(results?.Results)) {
// get encodedAutomationID to retrieve notification information
Expand All @@ -251,16 +261,16 @@ class Automation extends MetadataType {

// merge encodedAutomationID into results
for (const m of results.Results) {
resultsConverted[m.CustomerKey] = {
id: m.ObjectID,
key: m.CustomerKey,
name: m.Name,
programId: automationsLegacy.metadata[m.CustomerKey]?.id,
status: automationsLegacy.metadata[m.CustomerKey]?.status,
const key = m.CustomerKey || m.key;
resultsConverted[key] = {
id: m.ObjectID || m.id,
key: key,
name: m.Name || m.name,
programId: automationsLegacy.metadata[key]?.id,
status: automationsLegacy.metadata[key]?.status,
};
}
}

return { metadata: resultsConverted, type: this.definition.type };
}

Expand Down Expand Up @@ -362,7 +372,7 @@ class Automation extends MetadataType {
* @param {TYPE.AutomationItem} metadata a single automation
* @returns {TYPE.AutomationItem | void} parsed item
*/
static async postRetrieveTasks(metadata) {
static postRetrieveTasks(metadata) {
// folder
this.setFolderPath(metadata);
// automations are often skipped due to lack of support.
Expand Down

0 comments on commit 1099ed4

Please sign in to comment.