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:
parent
05ef4a05b4
commit
553c5c4927
@ -191,21 +191,26 @@ export class EventStore implements IEventStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private typeIsInteresting = (builder: Knex.QueryBuilder) =>
|
private typeIsInteresting =
|
||||||
builder
|
(environment?: string) => (builder: Knex.QueryBuilder) =>
|
||||||
.andWhere((inner) =>
|
builder
|
||||||
inner
|
.andWhere((inner) => {
|
||||||
.whereNotNull('feature_name')
|
inner
|
||||||
.whereNotIn('type', [FEATURE_CREATED, FEATURE_TAGGED])
|
.whereNotNull('feature_name')
|
||||||
.whereNot('type', 'LIKE', 'change-%'),
|
.whereNotIn('type', [FEATURE_CREATED, FEATURE_TAGGED])
|
||||||
)
|
.whereNot('type', 'LIKE', 'change-%');
|
||||||
.orWhereIn('type', [
|
if (environment) {
|
||||||
SEGMENT_UPDATED,
|
inner.where('environment', environment);
|
||||||
FEATURE_IMPORT,
|
}
|
||||||
FEATURES_IMPORTED,
|
return inner;
|
||||||
SEGMENT_CREATED,
|
})
|
||||||
SEGMENT_DELETED,
|
.orWhereIn('type', [
|
||||||
]);
|
SEGMENT_UPDATED,
|
||||||
|
FEATURE_IMPORT,
|
||||||
|
FEATURES_IMPORTED,
|
||||||
|
SEGMENT_CREATED,
|
||||||
|
SEGMENT_DELETED,
|
||||||
|
]);
|
||||||
|
|
||||||
async getMaxRevisionId(
|
async getMaxRevisionId(
|
||||||
largerThan: number = 0,
|
largerThan: number = 0,
|
||||||
@ -214,13 +219,9 @@ export class EventStore implements IEventStore {
|
|||||||
const stopTimer = this.metricTimer('getMaxRevisionId');
|
const stopTimer = this.metricTimer('getMaxRevisionId');
|
||||||
const query = this.db(TABLE)
|
const query = this.db(TABLE)
|
||||||
.max('id')
|
.max('id')
|
||||||
.where(this.typeIsInteresting)
|
.where(this.typeIsInteresting(environment))
|
||||||
.andWhere('id', '>=', largerThan);
|
.andWhere('id', '>=', largerThan);
|
||||||
|
|
||||||
if (environment) {
|
|
||||||
query.where('environment', environment);
|
|
||||||
}
|
|
||||||
|
|
||||||
const row = await query.first();
|
const row = await query.first();
|
||||||
stopTimer();
|
stopTimer();
|
||||||
return row?.max ?? 0;
|
return row?.max ?? 0;
|
||||||
@ -233,7 +234,7 @@ export class EventStore implements IEventStore {
|
|||||||
.from(TABLE)
|
.from(TABLE)
|
||||||
.where('id', '>', start)
|
.where('id', '>', start)
|
||||||
.andWhere('id', '<=', end)
|
.andWhere('id', '<=', end)
|
||||||
.andWhere(this.typeIsInteresting)
|
.andWhere(this.typeIsInteresting())
|
||||||
.orderBy('id', 'asc');
|
.orderBy('id', 'asc');
|
||||||
|
|
||||||
const rows = await query;
|
const rows = await query;
|
||||||
|
@ -18,7 +18,7 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
|
|
||||||
private revisionId: number;
|
private revisionId: number;
|
||||||
|
|
||||||
private maxRevisionId: Record<string, number> = {};
|
private maxRevisionId: Map<string, number> = new Map();
|
||||||
|
|
||||||
private flagResolver: IFlagResolver;
|
private flagResolver: IFlagResolver;
|
||||||
|
|
||||||
@ -73,10 +73,10 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
|
|
||||||
async updateMaxEnvironmentRevisionId(environment: string): Promise<number> {
|
async updateMaxEnvironmentRevisionId(environment: string): Promise<number> {
|
||||||
const envRevisionId = await this.eventStore.getMaxRevisionId(
|
const envRevisionId = await this.eventStore.getMaxRevisionId(
|
||||||
this.revisionId,
|
this.maxRevisionId[environment],
|
||||||
environment,
|
environment,
|
||||||
);
|
);
|
||||||
if (this.maxRevisionId[environment] < envRevisionId) {
|
if (this.maxRevisionId[environment] ?? 0 < envRevisionId) {
|
||||||
this.maxRevisionId[environment] = envRevisionId;
|
this.maxRevisionId[environment] = envRevisionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,8 +93,12 @@ export default class ConfigurationRevisionService extends EventEmitter {
|
|||||||
);
|
);
|
||||||
if (this.revisionId !== revisionId) {
|
if (this.revisionId !== revisionId) {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
'Updating feature configuration with new revision Id',
|
`Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
|
||||||
revisionId,
|
);
|
||||||
|
await Promise.allSettled(
|
||||||
|
Object.keys(this.maxRevisionId).map((environment) =>
|
||||||
|
this.updateMaxEnvironmentRevisionId(environment),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
this.revisionId = revisionId;
|
this.revisionId = revisionId;
|
||||||
if (emit) {
|
if (emit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user