Skip to content

Commit

Permalink
refactor: optimize applications overview (#6548)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjaanus committed Mar 14, 2024
1 parent 513d60c commit ba53bd7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/db/client-applications-store.ts
Expand Up @@ -292,6 +292,13 @@ export default class ClientApplicationsStore
appName: string,
): Promise<IApplicationOverview> {
const query = this.db
.with('metrics', (qb) => {
qb.distinct(
'cme.app_name',
'cme.environment',
'cme.feature_name',
).from('client_metrics_env as cme');
})
.select([
'f.project',
'cme.environment',
Expand All @@ -302,7 +309,7 @@ export default class ClientApplicationsStore
'a.strategies',
])
.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('client_instances as ci', function () {
this.on('ci.app_name', '=', 'cme.app_name').andOn(
Expand Down

0 comments on commit ba53bd7

Please sign in to comment.