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

refactor: optimize applications overview (#6548)

There was no need to join the entire metrics table, as it is a huge
table. We only needed all combinations of app_name, environment, and
feature_name. The new query retrieves all this data, which will then be
joined into the main query.
This commit is contained in:
Jaanus Sellin 2024-03-14 12:11:15 +02:00 committed by GitHub
parent 513d60c14d
commit ba53bd7bf9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -292,6 +292,13 @@ export default class ClientApplicationsStore
appName: string, appName: string,
): Promise<IApplicationOverview> { ): Promise<IApplicationOverview> {
const query = this.db const query = this.db
.with('metrics', (qb) => {
qb.distinct(
'cme.app_name',
'cme.environment',
'cme.feature_name',
).from('client_metrics_env as cme');
})
.select([ .select([
'f.project', 'f.project',
'cme.environment', 'cme.environment',
@ -302,7 +309,7 @@ export default class ClientApplicationsStore
'a.strategies', 'a.strategies',
]) ])
.from({ a: 'client_applications' }) .from({ a: 'client_applications' })
.leftJoin('client_metrics_env as cme', 'cme.app_name', 'a.app_name') .leftJoin('metrics as cme', 'cme.app_name', 'a.app_name')
.leftJoin('features as f', 'cme.feature_name', 'f.name') .leftJoin('features as f', 'cme.feature_name', 'f.name')
.leftJoin('client_instances as ci', function () { .leftJoin('client_instances as ci', function () {
this.on('ci.app_name', '=', 'cme.app_name').andOn( this.on('ci.app_name', '=', 'cme.app_name').andOn(