Skip to content

Commit

Permalink
chore: write only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jun 28, 2023
1 parent af8eb5d commit b3960eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,16 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op
}

public async unsetByValue(key: string): Promise<void> {
this.localConfig?.getKeysByValue(key).map((k) => this.localConfig?.unset(k));
this.globalConfig?.getKeysByValue(key).map((k) => this.globalConfig?.unset(k));
await this.localConfig?.write();
await this.globalConfig?.write();
const hasLocalWrites = this.localConfig
?.getKeysByValue(key)
.map((k) => this.localConfig?.unset(k))
.some(Boolean);
if (hasLocalWrites) await this.localConfig?.write();
const hasGlobalWrites = this.globalConfig
?.getKeysByValue(key)
.map((k) => this.globalConfig?.unset(k))
.some(Boolean);
if (hasGlobalWrites) await this.globalConfig?.write();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit/org/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ describe('Org Tests', () => {

it('should unset the alias and any configs', async () => {
const dev = await createOrgViaAuthInfo(testData.username);

const stateAggregator = await StateAggregator.getInstance();
await ConfigAggregator.create();
const orgTestData = new MockTestOrgData();
const org = await createOrgViaAuthInfo(orgTestData.username, orgTestData);
const username = ensureString(org.getUsername());
$$.setConfigStubContents('Config', { contents: { [OrgConfigProperties.TARGET_ORG]: username } });
expect($$.getConfigStubContents('Config')).to.deep.equal({ 'target-org': username });
const stateAggregator = await StateAggregator.getInstance();

await stateAggregator.aliases.setAndSave('deleteThisAlias', username);
expect(stateAggregator.aliases.getUsername('deleteThisAlias')).to.equal(username);
Expand Down

0 comments on commit b3960eb

Please sign in to comment.