1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-12 13:48:35 +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; const { child, projectId } = req.params;
if (this.config.flagResolver.isEnabled('dependentFeatures')) { if (this.config.flagResolver.isEnabled('dependentFeatures')) {
await this.dependentFeaturesService.deleteFeatureDependencies( await this.dependentFeaturesService.deleteFeaturesDependencies(
child, [child],
projectId, projectId,
req.user, req.user,
); );

View File

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

View File

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

View File

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

View File

@ -192,7 +192,14 @@ export default class ProjectArchiveController extends Controller {
const { features } = req.body; const { features } = req.body;
const { projectId } = req.params; 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(); res.status(202).end();
} }