1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

chore: remove redundant check for project names in db (#6311)

Skips the fetching project names from db part in the proxy-repository
that was done when the token had ALL_PROJECTS
This commit is contained in:
David Leek 2024-02-22 13:44:47 +01:00 committed by GitHub
parent dc214d376a
commit 3bfafcf87e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 19 deletions

View File

@ -11,7 +11,12 @@ import {
ITag,
PartialDeep,
} from '../../types';
import { DEFAULT_ENV, ensureStringValue, mapValues } from '../../util';
import {
ALL_PROJECTS,
DEFAULT_ENV,
ensureStringValue,
mapValues,
} from '../../util';
import EventEmitter from 'events';
import FeatureToggleStore from '../feature-toggle/feature-toggle-store';
import { Db } from '../../db/db';
@ -166,7 +171,10 @@ export default class FeatureToggleClientStore
.whereIn(['tag_type', 'tag_value'], featureQuery.tag);
query = query.whereIn('features.name', tagQuery);
}
if (featureQuery.project) {
if (
featureQuery.project &&
!featureQuery.project.includes(ALL_PROJECTS)
) {
query = query.whereIn('project', featureQuery.project);
}
if (featureQuery.namePrefix) {

View File

@ -10,6 +10,7 @@ import {
import NotFoundError from '../../../error/notfound-error';
import { IFeatureStrategiesStore } from '../types/feature-toggle-strategies-store-type';
import { IFeatureProjectUserParams } from '../feature-toggle-controller';
import { ALL_PROJECTS } from '../../../util';
interface ProjectEnvironment {
projectName: string;
@ -182,17 +183,20 @@ export default class FakeFeatureStrategiesStore
if (featureQuery.namePrefix) {
if (featureQuery.project) {
return (
toggle.name.startsWith(featureQuery.namePrefix) &&
featureQuery.project.some((project) =>
project.includes(toggle.project),
)
(toggle.name.startsWith(featureQuery.namePrefix) &&
featureQuery.project.some((project) =>
project.includes(toggle.project),
)) ||
featureQuery.project.includes(ALL_PROJECTS)
);
}
return toggle.name.startsWith(featureQuery.namePrefix);
}
if (featureQuery.project) {
return featureQuery.project.some((project) =>
project.includes(toggle.project),
return (
featureQuery.project.some((project) =>
project.includes(toggle.project),
) || featureQuery.project.includes(ALL_PROJECTS)
);
}
return toggle.archived === archived;

View File

@ -11,7 +11,7 @@ import {
mapFeaturesForClient,
mapSegmentsForClient,
} from '../features/playground/offline-unleash-client';
import { ALL_ENVS, ALL_PROJECTS } from '../util/constants';
import { ALL_ENVS } from '../util/constants';
import { UnleashEvents } from 'unleash-client';
import { Logger } from '../logger';
import ConfigurationRevisionService, {
@ -151,7 +151,7 @@ export class ProxyRepository
private async featuresForToken(): Promise<FeatureInterface[]> {
return mapFeaturesForClient(
await this.services.featureToggleServiceV2.getClientFeatures({
project: await this.projectIdsForToken(),
project: this.token.projects,
environment: this.environmentNameForToken(),
}),
);
@ -163,15 +163,6 @@ export class ProxyRepository
);
}
private async projectIdsForToken(): Promise<string[]> {
if (this.token.projects.includes(ALL_PROJECTS)) {
const allProjects = await this.stores.projectStore.getAll();
return allProjects.map((project) => project.id);
}
return this.token.projects;
}
private environmentNameForToken(): string {
if (this.token.environment === ALL_ENVS) {
return 'default';