1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00

bug fixes: only use environment in events with environment

This commit is contained in:
Gastón Fournier 2025-08-19 17:46:14 +02:00
parent 05ef4a05b4
commit 553c5c4927
No known key found for this signature in database
GPG Key ID: AF45428626E17A8E
2 changed files with 31 additions and 26 deletions

View File

@ -191,21 +191,26 @@ export class EventStore implements IEventStore {
}
}
private typeIsInteresting = (builder: Knex.QueryBuilder) =>
builder
.andWhere((inner) =>
inner
.whereNotNull('feature_name')
.whereNotIn('type', [FEATURE_CREATED, FEATURE_TAGGED])
.whereNot('type', 'LIKE', 'change-%'),
)
.orWhereIn('type', [
SEGMENT_UPDATED,
FEATURE_IMPORT,
FEATURES_IMPORTED,
SEGMENT_CREATED,
SEGMENT_DELETED,
]);
private typeIsInteresting =
(environment?: string) => (builder: Knex.QueryBuilder) =>
builder
.andWhere((inner) => {
inner
.whereNotNull('feature_name')
.whereNotIn('type', [FEATURE_CREATED, FEATURE_TAGGED])
.whereNot('type', 'LIKE', 'change-%');
if (environment) {
inner.where('environment', environment);
}
return inner;
})
.orWhereIn('type', [
SEGMENT_UPDATED,
FEATURE_IMPORT,
FEATURES_IMPORTED,
SEGMENT_CREATED,
SEGMENT_DELETED,
]);
async getMaxRevisionId(
largerThan: number = 0,
@ -214,13 +219,9 @@ export class EventStore implements IEventStore {
const stopTimer = this.metricTimer('getMaxRevisionId');
const query = this.db(TABLE)
.max('id')
.where(this.typeIsInteresting)
.where(this.typeIsInteresting(environment))
.andWhere('id', '>=', largerThan);
if (environment) {
query.where('environment', environment);
}
const row = await query.first();
stopTimer();
return row?.max ?? 0;
@ -233,7 +234,7 @@ export class EventStore implements IEventStore {
.from(TABLE)
.where('id', '>', start)
.andWhere('id', '<=', end)
.andWhere(this.typeIsInteresting)
.andWhere(this.typeIsInteresting())
.orderBy('id', 'asc');
const rows = await query;

View File

@ -18,7 +18,7 @@ export default class ConfigurationRevisionService extends EventEmitter {
private revisionId: number;
private maxRevisionId: Record<string, number> = {};
private maxRevisionId: Map<string, number> = new Map();
private flagResolver: IFlagResolver;
@ -73,10 +73,10 @@ export default class ConfigurationRevisionService extends EventEmitter {
async updateMaxEnvironmentRevisionId(environment: string): Promise<number> {
const envRevisionId = await this.eventStore.getMaxRevisionId(
this.revisionId,
this.maxRevisionId[environment],
environment,
);
if (this.maxRevisionId[environment] < envRevisionId) {
if (this.maxRevisionId[environment] ?? 0 < envRevisionId) {
this.maxRevisionId[environment] = envRevisionId;
}
@ -93,8 +93,12 @@ export default class ConfigurationRevisionService extends EventEmitter {
);
if (this.revisionId !== revisionId) {
this.logger.debug(
'Updating feature configuration with new revision Id',
revisionId,
`Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
);
await Promise.allSettled(
Object.keys(this.maxRevisionId).map((environment) =>
this.updateMaxEnvironmentRevisionId(environment),
),
);
this.revisionId = revisionId;
if (emit) {