mirror of
https://github.com/Unleash/unleash.git
synced 2025-11-24 20:06:55 +01: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(
|
this.logger.info(
|
||||||
`[etag] for query ${JSON.stringify(
|
`[etag] for query ${JSON.stringify(
|
||||||
query,
|
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');
|
const etagVariant = this.flagResolver.getVariant('etagVariant');
|
||||||
|
|||||||
@ -54,15 +54,15 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getMaxRevisionId(environment?: string): Promise<number> {
|
async getMaxRevisionId(environment?: string): Promise<number> {
|
||||||
if (environment && !this.maxRevisionId[environment]) {
|
if (environment) {
|
||||||
await this.updateMaxEnvironmentRevisionId(environment);
|
let maxEnvRevisionId = this.maxRevisionId.get(environment) ?? 0;
|
||||||
}
|
if (maxEnvRevisionId === 0) {
|
||||||
if (
|
maxEnvRevisionId =
|
||||||
environment &&
|
await this.updateMaxEnvironmentRevisionId(environment);
|
||||||
this.maxRevisionId[environment] &&
|
}
|
||||||
this.maxRevisionId[environment] > 0
|
if (maxEnvRevisionId > 0) {
|
||||||
) {
|
return maxEnvRevisionId;
|
||||||
return this.maxRevisionId[environment];
|
}
|
||||||
}
|
}
|
||||||
if (this.revisionId > 0) {
|
if (this.revisionId > 0) {
|
||||||
return this.revisionId;
|
return this.revisionId;
|
||||||
@ -72,21 +72,22 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateMaxEnvironmentRevisionId(environment: string): Promise<number> {
|
async updateMaxEnvironmentRevisionId(environment: string): Promise<number> {
|
||||||
const envRevisionId = await this.eventStore.getMaxRevisionId(
|
let maxRevId = this.maxRevisionId.get(environment) ?? 0;
|
||||||
this.maxRevisionId[environment],
|
const actualMax = await this.eventStore.getMaxRevisionId(
|
||||||
|
maxRevId,
|
||||||
environment,
|
environment,
|
||||||
);
|
);
|
||||||
if (this.maxRevisionId[environment] ?? 0 < envRevisionId) {
|
|
||||||
this.maxRevisionId[environment] = envRevisionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.flagResolver.isEnabled('debugEtag')) {
|
if (this.flagResolver.isEnabled('debugEtag')) {
|
||||||
this.logger.info(
|
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> {
|
async updateMaxRevisionId(emit: boolean = true): Promise<number> {
|
||||||
@ -98,17 +99,12 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
this.revisionId,
|
this.revisionId,
|
||||||
);
|
);
|
||||||
if (this.revisionId !== revisionId) {
|
if (this.revisionId !== revisionId) {
|
||||||
if (this.flagResolver.isEnabled('debugEtag')) {
|
const knownEnvironments = [...this.maxRevisionId.keys()];
|
||||||
this.logger.info(
|
this.logger.debug(
|
||||||
`[etag] Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
|
`Updating feature configuration with new revision Id ${revisionId} and all envs: ${knownEnvironments.join(', ')}`,
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
this.logger.debug(
|
|
||||||
`Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await Promise.allSettled(
|
await Promise.allSettled(
|
||||||
Object.keys(this.maxRevisionId).map((environment) =>
|
knownEnvironments.map((environment) =>
|
||||||
this.updateMaxEnvironmentRevisionId(environment),
|
this.updateMaxEnvironmentRevisionId(environment),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user