mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
refactor: segment read model used in proxy-repository (#6421)
This commit is contained in:
parent
76f379a4dc
commit
f3df7269cb
@ -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,
|
||||
@ -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),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
@ -164,7 +167,7 @@ export class ProxyRepository
|
||||
|
||||
private async segmentsForToken(): Promise<Segment[]> {
|
||||
return mapSegmentsForClient(
|
||||
await this.services.segmentService.getAll(),
|
||||
await this.stores.segmentReadModel.getAll(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -288,7 +288,6 @@ export const createServices = (
|
||||
const proxyService = new ProxyService(config, stores, {
|
||||
featureToggleServiceV2,
|
||||
clientMetricsServiceV2,
|
||||
segmentService,
|
||||
settingService,
|
||||
configurationRevisionService,
|
||||
});
|
||||
|
@ -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'
|
||||
|
@ -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;
|
||||
@ -82,6 +83,7 @@ export interface IUnleashStores {
|
||||
featureSearchStore: IFeatureSearchStore;
|
||||
inactiveUsersStore: IInactiveUsersStore;
|
||||
trafficDataUsageStore: ITrafficDataUsageStore;
|
||||
segmentReadModel: ISegmentReadModel;
|
||||
}
|
||||
|
||||
export {
|
||||
@ -124,4 +126,5 @@ export {
|
||||
ILastSeenStore,
|
||||
IFeatureSearchStore,
|
||||
ITrafficDataUsageStore,
|
||||
ISegmentReadModel,
|
||||
};
|
||||
|
2
src/test/fixtures/store.ts
vendored
2
src/test/fixtures/store.ts
vendored
@ -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: () => ({
|
||||
@ -93,6 +94,7 @@ const createStores: () => IUnleashStores = () => {
|
||||
featureSearchStore: new FakeFeatureSearchStore(),
|
||||
inactiveUsersStore: new FakeInactiveUsersStore(),
|
||||
trafficDataUsageStore: new FakeTrafficDataUsageStore(),
|
||||
segmentReadModel: new FakeSegmentReadModel(),
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user