mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-01 13:47:27 +02:00
chore: Etag log and code improvements (#10542)
This is a follow-up on the comments in https://github.com/Unleash/unleash/pull/10512 Mostly using get and set when accessing the Map
This commit is contained in:
parent
d11e8b2c81
commit
750a32f0e9
@ -373,7 +373,7 @@ export default class FeatureController extends Controller {
|
||||
this.logger.info(
|
||||
`[etag] for query ${JSON.stringify(
|
||||
query,
|
||||
)} is "${queryHash}:${revisionId}" (revision id query with env ${etagByEnvEnabled ? query.environment : undefined})`,
|
||||
)} is "${queryHash}:${revisionId}" query by env enabled? ${etagByEnvEnabled ? 'yes' : 'no'}. Querying with env ${etagByEnvEnabled ? query.environment : undefined})`,
|
||||
);
|
||||
}
|
||||
const etagVariant = this.flagResolver.getVariant('etagVariant');
|
||||
|
@ -54,15 +54,15 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
||||
}
|
||||
|
||||
async getMaxRevisionId(environment?: string): Promise<number> {
|
||||
if (environment && !this.maxRevisionId[environment]) {
|
||||
await this.updateMaxEnvironmentRevisionId(environment);
|
||||
}
|
||||
if (
|
||||
environment &&
|
||||
this.maxRevisionId[environment] &&
|
||||
this.maxRevisionId[environment] > 0
|
||||
) {
|
||||
return this.maxRevisionId[environment];
|
||||
if (environment) {
|
||||
let maxEnvRevisionId = this.maxRevisionId.get(environment) ?? 0;
|
||||
if (maxEnvRevisionId === 0) {
|
||||
maxEnvRevisionId =
|
||||
await this.updateMaxEnvironmentRevisionId(environment);
|
||||
}
|
||||
if (maxEnvRevisionId > 0) {
|
||||
return maxEnvRevisionId;
|
||||
}
|
||||
}
|
||||
if (this.revisionId > 0) {
|
||||
return this.revisionId;
|
||||
@ -72,21 +72,22 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
||||
}
|
||||
|
||||
async updateMaxEnvironmentRevisionId(environment: string): Promise<number> {
|
||||
const envRevisionId = await this.eventStore.getMaxRevisionId(
|
||||
this.maxRevisionId[environment],
|
||||
let maxRevId = this.maxRevisionId.get(environment) ?? 0;
|
||||
const actualMax = await this.eventStore.getMaxRevisionId(
|
||||
maxRevId,
|
||||
environment,
|
||||
);
|
||||
if (this.maxRevisionId[environment] ?? 0 < envRevisionId) {
|
||||
this.maxRevisionId[environment] = envRevisionId;
|
||||
}
|
||||
|
||||
if (this.flagResolver.isEnabled('debugEtag')) {
|
||||
this.logger.info(
|
||||
`[etag] Computed ETag for environment ${environment}: ${envRevisionId} stored as "${this.maxRevisionId[environment]}"`,
|
||||
`[etag] Computed ETag for environment ${environment}: ${actualMax} previous was ${maxRevId}`,
|
||||
);
|
||||
}
|
||||
if (maxRevId < actualMax) {
|
||||
this.maxRevisionId.set(environment, actualMax);
|
||||
maxRevId = actualMax;
|
||||
}
|
||||
|
||||
return this.maxRevisionId[environment];
|
||||
return maxRevId;
|
||||
}
|
||||
|
||||
async updateMaxRevisionId(emit: boolean = true): Promise<number> {
|
||||
@ -98,17 +99,12 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
||||
this.revisionId,
|
||||
);
|
||||
if (this.revisionId !== revisionId) {
|
||||
if (this.flagResolver.isEnabled('debugEtag')) {
|
||||
this.logger.info(
|
||||
`[etag] Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
|
||||
);
|
||||
} else {
|
||||
this.logger.debug(
|
||||
`Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
|
||||
);
|
||||
}
|
||||
const knownEnvironments = [...this.maxRevisionId.keys()];
|
||||
this.logger.debug(
|
||||
`Updating feature configuration with new revision Id ${revisionId} and all envs: ${knownEnvironments.join(', ')}`,
|
||||
);
|
||||
await Promise.allSettled(
|
||||
Object.keys(this.maxRevisionId).map((environment) =>
|
||||
knownEnvironments.map((environment) =>
|
||||
this.updateMaxEnvironmentRevisionId(environment),
|
||||
),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user