Skip to content

Commit

Permalink
chore: simplify solution
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jun 20, 2024
1 parent ecbe83d commit 42d7a2b
Showing 1 changed file with 5 additions and 32 deletions.
37 changes: 5 additions & 32 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,6 @@ export class Config extends ConfigFile<ConfigFile.Options, ConfigProperties> {
return keyBy(Config.allowedProperties, 'key');
}

private static findProperty(key: string): ConfigPropertyMeta {
const property = Config.allowedProperties.find((allowedProp) => allowedProp.key === key);

if (!property) {
throw messages.createError('unknownConfigKey', [key]);
}

return property;
}

/**
* Read, assign, and return the config contents.
*/
Expand Down Expand Up @@ -503,8 +493,11 @@ export class Config extends ConfigFile<ConfigFile.Options, ConfigProperties> {
* @param value The value of the property.
*/
public set<K extends Key<ConfigProperties>>(key: K, value: ConfigProperties[K]): ConfigProperties {
const property = Config.findProperty(key);
const property = Config.allowedProperties.find((allowedProp) => allowedProp.key === key);

if (!property) {
throw messages.createError('unknownConfigKey', [key]);
}
if (property.deprecated && property.newKey) {
// you're trying to set a deprecated key, but we'll set the new key instead
void Lifecycle.getInstance().emitWarning(messages.getMessage('deprecatedConfigKey', [key, property.newKey]));
Expand Down Expand Up @@ -597,31 +590,11 @@ export class Config extends ConfigFile<ConfigFile.Options, ConfigProperties> {

this.forEach((key, value) => {
if (this.getPropertyConfig(key).encrypted && isString(value)) {
if (encrypt) {
this.setEncryptedProperty(key, ensure(crypto.encrypt(value)));
} else {
this.set(key, ensure(crypto.decrypt(value)));
}
super.set(key, ensure(encrypt ? crypto.encrypt(value) : crypto.decrypt(value)));
}
});
}
}

/**
* Set an encrypted property without rerunning the validator. Should only be used by `cryptProperties` method.
*/
private setEncryptedProperty<K extends Key<ConfigProperties>>(key: K, value: ConfigProperties[K]): ConfigProperties {
const property = Config.findProperty(key);

if (property.deprecated && property.newKey) {
// you're trying to set a deprecated key, but we'll set the new key instead
void Lifecycle.getInstance().emitWarning(messages.getMessage('deprecatedConfigKey', [key, property.newKey]));
return this.set(property.newKey, value);
}

super.set(property.key, value);
return this.getContents();
}
}

/**
Expand Down

3 comments on commit 42d7a2b

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 42d7a2b Previous: ecbe83d Ratio
Child logger creation 481565 ops/sec (±1.43%) 479019 ops/sec (±0.52%) 0.99
Logging a string on root logger 869848 ops/sec (±9.52%) 769643 ops/sec (±9.76%) 0.88
Logging an object on root logger 592584 ops/sec (±7.69%) 586455 ops/sec (±7.80%) 0.99
Logging an object with a message on root logger 24150 ops/sec (±183.81%) 6342 ops/sec (±208.99%) 0.26
Logging an object with a redacted prop on root logger 470254 ops/sec (±11.44%) 442955 ops/sec (±5.90%) 0.94
Logging a nested 3-level object on root logger 23631 ops/sec (±183.45%) 374718 ops/sec (±8.41%) 15.86

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 42d7a2b Previous: ecbe83d Ratio
Logging a nested 3-level object on root logger 23631 ops/sec (±183.45%) 374718 ops/sec (±8.41%) 15.86

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 42d7a2b Previous: ecbe83d Ratio
Child logger creation 325931 ops/sec (±1.17%) 351661 ops/sec (±0.33%) 1.08
Logging a string on root logger 742782 ops/sec (±4.96%) 823379 ops/sec (±5.40%) 1.11
Logging an object on root logger 593401 ops/sec (±7.82%) 644119 ops/sec (±6.45%) 1.09
Logging an object with a message on root logger 7317 ops/sec (±201.08%) 1960 ops/sec (±243.21%) 0.27
Logging an object with a redacted prop on root logger 440422 ops/sec (±17.11%) 476110 ops/sec (±6.50%) 1.08
Logging a nested 3-level object on root logger 324988 ops/sec (±6.73%) 324421 ops/sec (±6.99%) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.