Skip to content

Commit

Permalink
#1803: optimize re-retrieval of journey after publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Jan 13, 2025
1 parent 61e2b98 commit 0194fa7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/Journey.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 20 additions & 25 deletions lib/metadataTypes/Journey.js
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,9 @@ class Journey extends MetadataType {
const statusUrls = [];
const executedKeyArr = [];
const refreshTransactionalKeys = [];
const metadataMap = upsertResults || (await this.retrieveForCache());
const metadataMap = upsertResults
? { metadata: upsertResults }
: await this.retrieveForCache();
const spinnerTransactional = yoctoSpinner({
text: `Publishing transactional journey…`,
});
Expand Down Expand Up @@ -1996,7 +1998,7 @@ class Journey extends MetadataType {
statusUrls.push({ key, statusUrl: response.statusUrl });
}
spinnerTransactional.start();
return key;
return journey[this.definition.keyField];
} catch (ex) {
spinnerTransactional.stop();
if (
Expand Down Expand Up @@ -2131,31 +2133,24 @@ class Journey extends MetadataType {
Util.logger.info('Re-retrieving published journeys');
const retriever = new Retriever(this.properties, this.buObject);
try {
/** @type {MetadataTypeItem[]} */
let updatedJourneys;
if (upsertResults) {
// if we are in upsert mode, we already have everything else cached and can simply retrieve the updated journeys
const updatedJourneysMap = await this.retrieveForCache();

updatedJourneys = Object.values(updatedJourneysMap.metadata);
} else {
// if we are in publish-only mode, we need to retrieve the updated journeys and all dependencies
const updatedJourneyRetrieve = await retriever.retrieve(
['journey'],
executedKeyArr.filter(Boolean)
);
// we need to retrieve the updated journeys and all dependencies
const updatedJourneyRetrieve = await retriever.retrieve(
['journey'],
executedKeyArr.filter(Boolean)
);

updatedJourneys =
updatedJourneyRetrieve?.journey?.length > 1
? Object.values(
updatedJourneyRetrieve?.journey.reduce(
(previousValue, currentValue) =>
Object.assign(previousValue, currentValue),
{}
)
/** @type {MetadataTypeItem[]} */
const updatedJourneys =
updatedJourneyRetrieve?.journey?.length > 1
? Object.values(
updatedJourneyRetrieve?.journey.reduce(
(previousValue, currentValue) =>
Object.assign(previousValue, currentValue),
{}
)
: Object.values(updatedJourneyRetrieve?.journey[0]);
}
)
: Object.values(updatedJourneyRetrieve?.journey[0]);

if (updatedJourneys) {
// regardless of upsert vs publish-only mode, we need to retrieve the events/transactionalEmail and their dependencies
const updatedEvents = [];
Expand Down

0 comments on commit 0194fa7

Please sign in to comment.