Skip to content

Commit

Permalink
#139: streamline performance and log output
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Feb 24, 2023
1 parent c1ba8c7 commit 128f691
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions lib/metadataTypes/AccountUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class AccountUser extends MetadataType {
/**
* prepares a item for deployment
*
* @param {TYPE.MetadataTypeItem} metadata of a single item
* @returns {TYPE.MetadataTypeItem} metadata object
* @param {TYPE.AccountUserDocument} metadata of a single item
* @returns {TYPE.AccountUserDocument} metadata object
*/
static async preDeployTasks(metadata) {
delete metadata.type__c;
Expand Down Expand Up @@ -150,8 +150,8 @@ class AccountUser extends MetadataType {
* @param {TYPE.MetadataTypeItem} metadata single metadata itme
* @param {string} metadataKey key of item we are looking at
* @param {boolean} hasError error flag from previous code
* @param {TYPE.MetadataTypeItemDiff[]} metadataToUpdate list of items to update
* @param {TYPE.MetadataTypeItem[]} metadataToCreate list of items to create
* @param {TYPE.AccountUserDocumentDiff[]} metadataToUpdate list of items to update
* @param {TYPE.AccountUserDocument[]} metadataToCreate list of items to create
* @returns {void}
*/
static createOrUpdate(metadata, metadataKey, hasError, metadataToUpdate, metadataToCreate) {
Expand Down Expand Up @@ -350,18 +350,18 @@ class AccountUser extends MetadataType {
if (addedRoleNames.length) {
Util.logger.info(
Util.getGrayMsg(
` - Adding role-assignment (${item.after.Name}): ${addedRoleNames.join(
', '
)}`
` - adding role-assignment (${item.after.CustomerKey} / ${
item.after.Name
}): ${addedRoleNames.join(', ')}`
)
);
}
if (deletedRoleIds.length) {
Util.logger.info(
Util.getGrayMsg(
` - Removing role-assignment (${item.after.Name}): ${deletedRoleNames.join(
', '
)}`
` - removing role-assignment (${item.after.CustomerKey} / ${
item.after.Name
}): ${deletedRoleNames.join(', ')}`
)
);
// add deleted roles to payload with IsDelete=true
Expand Down Expand Up @@ -402,36 +402,24 @@ class AccountUser extends MetadataType {
static async _retrieve(retrieveDir, key) {
this.userIdBuMap = {};

if (retrieveDir) {
// get BUs that each users have access to
const optionsBUs = {};
Util.logger.info(' - Caching dependent Metadata: AccountUserAccount');
const resultsBatch = (
await this.client.soap.retrieveBulk(
'AccountUserAccount',
[
'AccountUser.AccountUserID',
'AccountUser.UserID',
'Account.ID',
'Account.Name',
],
optionsBUs
)
).Results;
for (const item of resultsBatch) {
this.userIdBuMap[item.AccountUser.AccountUserID] =
this.userIdBuMap[item.AccountUser.AccountUserID] || [];
// push to array if not already in array
if (
!this.userIdBuMap[item.AccountUser.AccountUserID].some(
(bu) => bu.ID === item.Account.ID
)
) {
this.userIdBuMap[item.AccountUser.AccountUserID].push({
ID: item.Account.ID,
Name: item.Account.Name,
});
}
// get BUs that each users have access to
const optionsBUs = {};
Util.logger.info(
' - Caching dependent Metadata: AccountUserAccount (Business Unit assignments)'
);
const resultsBatch = (
await this.client.soap.retrieveBulk(
'AccountUserAccount',
['AccountUser.AccountUserID', 'Account.ID'],
optionsBUs
)
).Results;
for (const item of resultsBatch) {
this.userIdBuMap[item.AccountUser.AccountUserID] =
this.userIdBuMap[item.AccountUser.AccountUserID] || [];
// push to array if not already in array
if (!this.userIdBuMap[item.AccountUser.AccountUserID].includes(item.Account.ID)) {
this.userIdBuMap[item.AccountUser.AccountUserID].push(item.Account.ID);
}
}
// get actual user details
Expand Down Expand Up @@ -802,9 +790,7 @@ class AccountUser extends MetadataType {
metadata.type__c = 'User';
}

metadata.AssociatedBusinessUnits__c = this.userIdBuMap[metadata.ID]
? this.userIdBuMap[metadata.ID].map((item) => item.ID)
: [];
metadata.AssociatedBusinessUnits__c = this.userIdBuMap[metadata.ID] || [];

// make roles easily accessible
let roles;
Expand Down

0 comments on commit 128f691

Please sign in to comment.