diff --git a/src/lib/features/feature-toggle/converters/feature-toggle-row-converter.ts b/src/lib/features/feature-toggle/converters/feature-toggle-row-converter.ts index d2e9c52f19..830bc2511e 100644 --- a/src/lib/features/feature-toggle/converters/feature-toggle-row-converter.ts +++ b/src/lib/features/feature-toggle/converters/feature-toggle-row-converter.ts @@ -91,6 +91,10 @@ export class FeatureToggleRowConverter { enabled: row.enabled || false, }; + if (!newEnvironment.name || !newEnvironment.lastSeenAt) { + return; + } + feature.environments.push(newEnvironment); }; diff --git a/src/lib/features/feature-toggle/feature-toggle-store.ts b/src/lib/features/feature-toggle/feature-toggle-store.ts index 437360f998..bc0b6a060a 100644 --- a/src/lib/features/feature-toggle/feature-toggle-store.ts +++ b/src/lib/features/feature-toggle/feature-toggle-store.ts @@ -172,7 +172,7 @@ export default class FeatureToggleStore implements IFeatureToggleStore { builder.addSelectColumn('ft.tag_type as tag_type'); if (this.flagResolver.isEnabled('useLastSeenRefactor')) { - builder.withLastSeenByEnvironment(); + builder.withLastSeenByEnvironment(archived); builder.addSelectColumn( 'last_seen_at_metrics.last_seen_at as env_last_seen_at', ); @@ -262,7 +262,8 @@ export default class FeatureToggleStore implements IFeatureToggleStore { 'features.archived_at as archived_at', ]); - builder.query('features').withLastSeenByEnvironment(); + const archived = true; + builder.query('features').withLastSeenByEnvironment(archived); builder.addSelectColumn( 'last_seen_at_metrics.last_seen_at as env_last_seen_at', diff --git a/src/lib/features/feature-toggle/feature-toggle-strategies-store.ts b/src/lib/features/feature-toggle/feature-toggle-strategies-store.ts index ca88b8c759..417f8e40b0 100644 --- a/src/lib/features/feature-toggle/feature-toggle-strategies-store.ts +++ b/src/lib/features/feature-toggle/feature-toggle-strategies-store.ts @@ -176,7 +176,7 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore { flagResolver: IFlagResolver, ) { this.db = db; - this.logger = getLogger('feature-toggle-store.ts'); + this.logger = getLogger('feature-toggle-strategies-store.ts'); this.timer = (action) => metricsHelper.wrapTimer(eventBus, DB_TIME, { store: 'feature-toggle-strategies', diff --git a/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts b/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts index 27b3c6bf21..c55acdd496 100644 --- a/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts +++ b/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts @@ -93,8 +93,16 @@ export class FeatureToggleListBuilder { return this; } - withLastSeenByEnvironment = () => { - this.internalQuery.leftJoin('last_seen_at_metrics', 'last_seen_at_metrics.feature_name', 'features.name'); + withLastSeenByEnvironment = (archived = false) => { + if (archived) { + this.internalQuery.leftJoin('last_seen_at_metrics', function() { + this.on('last_seen_at_metrics.feature_name', '=', 'features.name') + .andOnNotNull('features.archived_at'); + }) + } else { + this.internalQuery.leftJoin('last_seen_at_metrics', 'last_seen_at_metrics.feature_name', 'features.name'); + } + return this; }