Skip to content

Commit

Permalink
#1270: prevent saving in loop for type asset as thats done in Asset.r…
Browse files Browse the repository at this point in the history
…eplaceCbReference()
  • Loading branch information
JoernBerkefeld committed Jun 2, 2024
1 parent 744b0fc commit e67fb49
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions lib/metadataTypes/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2166,12 +2166,65 @@ class Asset extends MetadataType {
return responseItem;
}
/**
* empty dummy method as assets are note saved via the central method
* this iterates over all items found in the retrieve folder and executes the type-specific method for replacing references
*
* @returns {MetadataTypeItem} saved metadata
* @param {MetadataTypeMap} metadataMap list of metadata (keyField => metadata)
* @param {string} retrieveDir retrieve dir including cred and bu
* @returns {Promise.<string[]>} Returns list of keys for which references were replaced
*/
static async saveToDisk() {
return;
static async replaceCbReferenceLoop(metadataMap, retrieveDir) {
const keysForDeploy = [];
if (!metadataMap) {
// if a type was skipped e.g. because it shall only be looked at on the parent then we would expect metadataMap to be undefined
return keysForDeploy;
}

const fromDescription = Util.OPTIONS.referenceFrom
.map((from) => 'ContentBlockBy' + Util.capitalizeFirstLetter(from))
.join(' and ');

if (Object.keys(metadataMap).length) {
Util.logger.info(`Searching ${this.definition.type} for ${fromDescription}:`);
// const baseDir = [retrieveDir, ...this.definition.type.split('-')];
const deployMap = {};

for (const key in metadataMap) {
const item = metadataMap[key];
if (this.isFiltered(item, true) || this.isFiltered(item, false)) {
// we would not have saved these items to disk but they exist in the cache and hence need to be skipped here

continue;
}

try {
// add key but make sure to turn it into string or else numeric keys will be filtered later
deployMap[key] = await this.replaceCbReference(item, retrieveDir);

// ! this method is equal to the super version except that it does not run saveToDisk here
// await this.saveToDisk(deployMap, key, baseDir);

keysForDeploy.push(key + '');
Util.logger.info(` - added ${this.definition.type} to update queue: ${key}`);
} catch (ex) {
if (ex.code !== 200) {
// dont print error if we simply did not find relevant content blocks
Util.logger.errorStack(ex, ex.message);
}
Util.logger.info(
Util.getGrayMsg(
` ☇ skipping ${this.definition.type} ${
item[this.definition.keyField]
}: no ${fromDescription} found`
)
);
}
}

Util.logger.info(
`Found ${keysForDeploy.length} ${this.definition.type}${keysForDeploy.length === 1 ? '' : 's'} to update`
);
}
return keysForDeploy;
}
}

Expand Down

0 comments on commit e67fb49

Please sign in to comment.