diff --git a/src/lib/features/project/project-read-model.test.ts b/src/lib/features/project/project-read-model.test.ts index c58e2af507..2f2e17cfbe 100644 --- a/src/lib/features/project/project-read-model.test.ts +++ b/src/lib/features/project/project-read-model.test.ts @@ -4,6 +4,7 @@ import type { IFeatureToggleStore } from '../feature-toggle/types/feature-toggle import type { IEventStore, IFlagResolver, + ILastSeenStore, IProjectReadModel, IProjectStore, } from '../../types'; @@ -15,6 +16,7 @@ let flagStore: IFeatureToggleStore; let projectStore: IProjectStore; let eventStore: IEventStore; let projectReadModel: IProjectReadModel; +let lastSeenStore: ILastSeenStore; const alwaysOnFlagResolver = { isEnabled() { @@ -32,6 +34,7 @@ beforeAll(async () => { projectStore = db.stores.projectStore; eventStore = db.stores.eventStore; flagStore = db.stores.featureToggleStore; + lastSeenStore = db.stores.lastSeenStore; }); afterAll(async () => { @@ -148,12 +151,10 @@ test('it uses the last flag metrics received for lastReportedFlagUsage', async ( await flagStore.create(projectId, { name: flagName, createdByUserId: 1 }); - await flagStore.setLastSeen([ + await lastSeenStore.setLastSeen([ { featureName: flagName, environment: 'development' }, ]); - const flag = await flagStore.get(flagName); - const result = await projectReadModel.getProjectsForAdminUi(); - expect(result[0].lastReportedFlagUsage).toEqual(flag.lastSeenAt); + expect(result[0].lastReportedFlagUsage).not.toBeNull(); }); diff --git a/src/lib/features/project/project-read-model.ts b/src/lib/features/project/project-read-model.ts index e3b03d7761..4bdd703e06 100644 --- a/src/lib/features/project/project-read-model.ts +++ b/src/lib/features/project/project-read-model.ts @@ -69,6 +69,11 @@ export class ProjectReadModel implements IProjectReadModel { const projectTimer = this.timer('getProjectsForAdminUi'); let projects = this.db(TABLE) .leftJoin('features', 'features.project', 'projects.id') + .leftJoin( + 'last_seen_at_metrics', + 'features.name', + 'last_seen_at_metrics.feature_name', + ) .leftJoin( 'project_settings', 'project_settings.project', @@ -99,7 +104,7 @@ export class ProjectReadModel implements IProjectReadModel { this.db.raw( 'projects.id, projects.name, projects.description, projects.health, projects.created_at, ' + 'count(DISTINCT features.name) FILTER (WHERE features.archived_at is null) AS number_of_features, ' + - 'MAX(features.last_seen_at) AS last_usage,' + + 'MAX(last_seen_at_metrics.last_seen_at) AS last_usage, ' + 'MAX(events.created_at) AS last_updated', ), 'project_settings.project_mode',