mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	1-3121: fix wrong counting for unhealthy flags (#8772)
This PR fixes the counting of unhealthy flags for the project status page. The issue was that we were looking for `archived = false`, but we don't set that flag in the db anymore. Instead, we set the `archived_at` date, which should be null if the flag is unarchived.
This commit is contained in:
		
							parent
							
								
									ec44c5b5e4
								
							
						
					
					
						commit
						20749cf771
					
				| @ -7,7 +7,8 @@ export class ProjectStaleFlagsReadModel implements IProjectStaleFlagsReadModel { | |||||||
|     async getStaleFlagCountForProject(projectId: string): Promise<number> { |     async getStaleFlagCountForProject(projectId: string): Promise<number> { | ||||||
|         const result = await this.db('features') |         const result = await this.db('features') | ||||||
|             .count() |             .count() | ||||||
|             .where({ project: projectId, archived: false }) |             .whereNull('archived_at') | ||||||
|  |             .where({ project: projectId }) | ||||||
|             .where((builder) => |             .where((builder) => | ||||||
|                 builder |                 builder | ||||||
|                     .orWhere({ stale: true }) |                     .orWhere({ stale: true }) | ||||||
|  | |||||||
| @ -264,35 +264,45 @@ test('project status includes stale flags', async () => { | |||||||
|         {} as IUser, |         {} as IUser, | ||||||
|         {} as IAuditUser, |         {} as IAuditUser, | ||||||
|     ); |     ); | ||||||
|     const createFlagInState = async ( |  | ||||||
|         name: string, |  | ||||||
|         state?: Object, |  | ||||||
|         projectId?: string, |  | ||||||
|     ) => { |  | ||||||
|         await app.createFeature(name, projectId); |  | ||||||
|         if (state) { |  | ||||||
|             await db.rawDatabase('features').update(state).where({ name }); |  | ||||||
|         } |  | ||||||
|     }; |  | ||||||
| 
 | 
 | ||||||
|     await createFlagInState('stale-flag', { stale: true }); |     function cartesianProduct(...arrays: any[][]): any[][] { | ||||||
|     await createFlagInState('potentially-stale-flag', { |         return arrays.reduce( | ||||||
|         potentially_stale: true, |             (acc, array) => { | ||||||
|     }); |                 return acc.flatMap((accItem) => | ||||||
|     await createFlagInState('potentially-stale-and-stale-flag', { |                     array.map((item) => [...accItem, item]), | ||||||
|         potentially_stale: true, |  | ||||||
|         stale: true, |  | ||||||
|     }); |  | ||||||
|     await createFlagInState('non-stale-flag'); |  | ||||||
|     await createFlagInState('archived-stale-flag', { |  | ||||||
|         archived: true, |  | ||||||
|         stale: true, |  | ||||||
|     }); |  | ||||||
|     await createFlagInState( |  | ||||||
|         'stale-other-project', |  | ||||||
|         { stale: true }, |  | ||||||
|         otherProject.id, |  | ||||||
|                 ); |                 ); | ||||||
|  |             }, | ||||||
|  |             [[]] as any[][], | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // of all 16 (2^4) permutations, only 3 are unhealthy flags in a given project.
 | ||||||
|  |     const combinations = cartesianProduct( | ||||||
|  |         [false, true], // stale
 | ||||||
|  |         [false, true], // potentially stale
 | ||||||
|  |         [false, true], // archived
 | ||||||
|  |         ['default', otherProject.id], // project
 | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     for (const [stale, potentiallyStale, archived, project] of combinations) { | ||||||
|  |         const name = `flag-${project}-stale-${stale}-potentially-stale-${potentiallyStale}-archived-${archived}`; | ||||||
|  |         await app.createFeature( | ||||||
|  |             { | ||||||
|  |                 name, | ||||||
|  |                 stale, | ||||||
|  |             }, | ||||||
|  |             project, | ||||||
|  |         ); | ||||||
|  |         if (potentiallyStale) { | ||||||
|  |             await db | ||||||
|  |                 .rawDatabase('features') | ||||||
|  |                 .update('potentially_stale', true) | ||||||
|  |                 .where({ name }); | ||||||
|  |         } | ||||||
|  |         if (archived) { | ||||||
|  |             await app.archiveFeature(name, project); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     const { body } = await app.request |     const { body } = await app.request | ||||||
|         .get('/api/admin/projects/default/status') |         .get('/api/admin/projects/default/status') | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user