Skip to content

Commit

Permalink
refactor: segment read model used in proxy-repository (#6421)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Mar 4, 2024
1 parent 76f379a commit f3df726
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/lib/db/index.ts
Expand Up @@ -42,6 +42,7 @@ import LastSeenStore from '../features/metrics/last-seen/last-seen-store';
import FeatureSearchStore from '../features/feature-search/feature-search-store';
import { InactiveUsersStore } from '../users/inactive/inactive-users-store';
import { TrafficDataUsageStore } from '../features/traffic-data-usage/traffic-data-usage-store';
import { SegmentReadModel } from '../features/segment/segment-read-model';

export const createStores = (
config: IUnleashConfig,
Expand Down Expand Up @@ -145,6 +146,7 @@ export const createStores = (
featureSearchStore: new FeatureSearchStore(db, eventBus, getLogger),
inactiveUsersStore: new InactiveUsersStore(db, eventBus, getLogger),
trafficDataUsageStore: new TrafficDataUsageStore(db, getLogger),
segmentReadModel: new SegmentReadModel(db),
};
};

Expand Down
9 changes: 6 additions & 3 deletions src/lib/proxy/proxy-repository.ts
Expand Up @@ -21,11 +21,14 @@ import { PROXY_FEATURES_FOR_TOKEN_TIME } from '../metric-events';

type Config = Pick<IUnleashConfig, 'getLogger' | 'frontendApi' | 'eventBus'>;

type Stores = Pick<IUnleashStores, 'projectStore' | 'eventStore'>;
type Stores = Pick<
IUnleashStores,
'projectStore' | 'eventStore' | 'segmentReadModel'
>;

type Services = Pick<
IUnleashServices,
'featureToggleServiceV2' | 'segmentService' | 'configurationRevisionService'
'featureToggleServiceV2' | 'configurationRevisionService'
>;

export class ProxyRepository
Expand Down Expand Up @@ -164,7 +167,7 @@ export class ProxyRepository

private async segmentsForToken(): Promise<Segment[]> {
return mapSegmentsForClient(
await this.services.segmentService.getAll(),
await this.stores.segmentReadModel.getAll(),
);
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/services/index.ts
Expand Up @@ -288,7 +288,6 @@ export const createServices = (
const proxyService = new ProxyService(config, stores, {
featureToggleServiceV2,
clientMetricsServiceV2,
segmentService,
settingService,
configurationRevisionService,
});
Expand Down
6 changes: 4 additions & 2 deletions src/lib/services/proxy-service.ts
Expand Up @@ -23,12 +23,14 @@ type Config = Pick<
'getLogger' | 'frontendApi' | 'frontendApiOrigins' | 'eventBus'
>;

type Stores = Pick<IUnleashStores, 'projectStore' | 'eventStore'>;
type Stores = Pick<
IUnleashStores,
'projectStore' | 'eventStore' | 'segmentReadModel'
>;

type Services = Pick<
IUnleashServices,
| 'featureToggleServiceV2'
| 'segmentService'
| 'clientMetricsServiceV2'
| 'settingService'
| 'configurationRevisionService'
Expand Down
3 changes: 3 additions & 0 deletions src/lib/types/stores.ts
Expand Up @@ -39,6 +39,7 @@ import { ILastSeenStore } from '../features/metrics/last-seen/types/last-seen-st
import { IFeatureSearchStore } from '../features/feature-search/feature-search-store-type';
import { IInactiveUsersStore } from '../users/inactive/types/inactive-users-store-type';
import { ITrafficDataUsageStore } from '../features/traffic-data-usage/traffic-data-usage-store-type';
import { ISegmentReadModel } from '../features/segment/segment-read-model-type';

export interface IUnleashStores {
accessStore: IAccessStore;
Expand Down Expand Up @@ -82,6 +83,7 @@ export interface IUnleashStores {
featureSearchStore: IFeatureSearchStore;
inactiveUsersStore: IInactiveUsersStore;
trafficDataUsageStore: ITrafficDataUsageStore;
segmentReadModel: ISegmentReadModel;
}

export {
Expand Down Expand Up @@ -124,4 +126,5 @@ export {
ILastSeenStore,
IFeatureSearchStore,
ITrafficDataUsageStore,
ISegmentReadModel,
};
2 changes: 2 additions & 0 deletions src/test/fixtures/store.ts
Expand Up @@ -42,6 +42,7 @@ import { FakeLastSeenStore } from '../../lib/features/metrics/last-seen/fake-las
import FakeFeatureSearchStore from '../../lib/features/feature-search/fake-feature-search-store';
import { FakeInactiveUsersStore } from '../../lib/users/inactive/fakes/fake-inactive-users-store';
import { FakeTrafficDataUsageStore } from '../../lib/features/traffic-data-usage/fake-traffic-data-usage-store';
import { FakeSegmentReadModel } from '../../lib/features/segment/fake-segment-read-model';

const db = {
select: () => ({
Expand Down Expand Up @@ -93,6 +94,7 @@ const createStores: () => IUnleashStores = () => {
featureSearchStore: new FakeFeatureSearchStore(),
inactiveUsersStore: new FakeInactiveUsersStore(),
trafficDataUsageStore: new FakeTrafficDataUsageStore(),
segmentReadModel: new FakeSegmentReadModel(),
};
};

Expand Down

0 comments on commit f3df726

Please sign in to comment.