mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: increase performance of outdated SDK query (#7226)
Joining might not always be the best solution. If a table contains too much data, and you later run sorting on top of it, it will be slow. In this case, we will first reduce the instances table to a minimal version because instances usually share the same SDK versions. Only after that, we join. Based on some customer data, we reduced query time from 3000ms to 60ms. However, this will vary based on the number of instances the customer has.
This commit is contained in:
parent
de74faac46
commit
3c73ce9dd9
@ -222,15 +222,22 @@ export default class ClientInstanceStore implements IClientInstanceStore {
|
||||
projectId: string,
|
||||
): Promise<{ sdkVersion: string; applications: string[] }[]> {
|
||||
const rows = await this.db
|
||||
.with(
|
||||
'instances',
|
||||
this.db
|
||||
.select('app_name', 'sdk_version')
|
||||
.distinct()
|
||||
.from('client_instances'),
|
||||
)
|
||||
.select([
|
||||
'ci.sdk_version as sdkVersion',
|
||||
'i.sdk_version as sdkVersion',
|
||||
this.db.raw('ARRAY_AGG(DISTINCT cme.app_name) as applications'),
|
||||
])
|
||||
.from('client_metrics_env as cme')
|
||||
.leftJoin('features as f', 'f.name', 'cme.feature_name')
|
||||
.leftJoin('client_instances as ci', 'ci.app_name', 'cme.app_name')
|
||||
.leftJoin('instances as i', 'i.app_name', 'cme.app_name')
|
||||
.where('f.project', projectId)
|
||||
.groupBy('ci.sdk_version');
|
||||
.groupBy('i.sdk_version');
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user