1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-06 01:15:28 +02:00

feat: remove dependency on archive (#5040)

This commit is contained in:
Mateusz Kwasniewski 2023-10-16 08:59:34 +02:00 committed by GitHub
parent 010332e171
commit c41f23ae54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 20 deletions

View File

@ -226,8 +226,8 @@ export default class DependentFeaturesController extends Controller {
const { child, projectId } = req.params;
if (this.config.flagResolver.isEnabled('dependentFeatures')) {
await this.dependentFeaturesService.deleteFeatureDependencies(
child,
await this.dependentFeaturesService.deleteFeaturesDependencies(
[child],
projectId,
req.user,
);

View File

@ -163,32 +163,34 @@ export class DependentFeaturesService {
});
}
async deleteFeatureDependencies(
feature: string,
async deleteFeaturesDependencies(
features: string[],
projectId: string,
user: User,
): Promise<void> {
await this.stopWhenChangeRequestsEnabled(projectId, user);
return this.unprotectedDeleteFeatureDependencies(
feature,
return this.unprotectedDeleteFeaturesDependencies(
features,
projectId,
extractUsernameFromUser(user),
);
}
async unprotectedDeleteFeatureDependencies(
feature: string,
async unprotectedDeleteFeaturesDependencies(
features: string[],
projectId: string,
user: string,
): Promise<void> {
await this.dependentFeaturesStore.deleteAll([feature]);
await this.eventService.storeEvent({
type: 'feature-dependencies-removed',
project: projectId,
featureName: feature,
createdBy: user,
});
await this.dependentFeaturesStore.deleteAll(features);
await this.eventService.storeEvents(
features.map((feature) => ({
type: 'feature-dependencies-removed',
project: projectId,
featureName: feature,
createdBy: user,
})),
);
}
async getParentOptions(feature: string): Promise<string[]> {

View File

@ -777,10 +777,12 @@ export default class ProjectFeaturesController extends Controller {
res: Response<void>,
): Promise<void> {
const { featureName, projectId } = req.params;
await this.featureService.archiveToggle(
featureName,
req.user,
projectId,
await this.startTransaction(async (tx) =>
this.transactionalFeatureToggleService(tx).archiveToggle(
featureName,
req.user,
projectId,
),
);
res.status(202).send();
}

View File

@ -1510,6 +1510,13 @@ class FeatureToggleService {
await this.validateNoChildren(featureName);
await this.featureToggleStore.archive(featureName);
if (projectId) {
await this.dependentFeaturesService.unprotectedDeleteFeaturesDependencies(
[featureName],
projectId,
createdBy,
);
}
await this.eventService.storeEvent(
new FeatureArchivedEvent({
@ -1551,6 +1558,11 @@ class FeatureToggleService {
featureNames,
);
await this.featureToggleStore.batchArchive(featureNames);
await this.dependentFeaturesService.unprotectedDeleteFeaturesDependencies(
featureNames,
projectId,
createdBy,
);
await this.eventService.storeEvents(
features.map(

View File

@ -192,7 +192,14 @@ export default class ProjectArchiveController extends Controller {
const { features } = req.body;
const { projectId } = req.params;
await this.featureService.archiveToggles(features, req.user, projectId);
await this.startTransaction(async (tx) =>
this.transactionalFeatureToggleService(tx).archiveToggles(
features,
req.user,
projectId,
),
);
res.status(202).end();
}