-
-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: rework application overview db query #8518
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -313,29 +313,40 @@ export default class ClientApplicationsStore | |||
), | ||||
]) | ||||
.from('client_metrics_env as cme') | ||||
.where('cme.app_name', appName) | ||||
.leftJoin('features as f', 'f.name', 'cme.feature_name') | ||||
.groupBy('cme.app_name', 'cme.environment', 'f.project'); | ||||
}) | ||||
.with('instances', (qb) => { | ||||
qb.select([ | ||||
'ci.app_name', | ||||
'ci.environment', | ||||
this.db.raw( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we count in database level, instead of joining and returning all. |
||||
'COUNT(DISTINCT ci.instance_id) as unique_instance_count', | ||||
), | ||||
this.db.raw( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also count these in database. |
||||
'ARRAY_AGG(DISTINCT ci.sdk_version) as sdk_versions', | ||||
), | ||||
this.db.raw('MAX(ci.last_seen) as latest_last_seen'), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also last seen, max will be taken, instead of doing it in memory. |
||||
]) | ||||
.from('client_instances as ci') | ||||
.where('ci.app_name', appName) | ||||
.groupBy('ci.app_name', 'ci.environment'); | ||||
}) | ||||
.select([ | ||||
'm.project', | ||||
'm.environment', | ||||
'm.features', | ||||
'ci.instance_id', | ||||
'ci.sdk_version', | ||||
'ci.last_seen', | ||||
'a.strategies', | ||||
'i.unique_instance_count', | ||||
'i.sdk_versions', | ||||
'i.latest_last_seen', | ||||
'ca.strategies', | ||||
]) | ||||
.from({ a: 'client_applications' }) | ||||
.leftJoin('metrics as m', 'm.app_name', 'a.app_name') | ||||
.leftJoin('client_instances as ci', function () { | ||||
this.on('ci.app_name', '=', 'm.app_name').andOn( | ||||
'ci.environment', | ||||
'=', | ||||
'm.environment', | ||||
); | ||||
}) | ||||
.where('a.app_name', appName) | ||||
.from('client_applications as ca') | ||||
.leftJoin('metrics as m', 'm.app_name', 'ca.app_name') | ||||
.leftJoin('instances as i', 'i.environment', 'm.environment') | ||||
.orderBy('m.environment', 'asc'); | ||||
console.log(query.toQuery()); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
const rows = await query; | ||||
stopTimer(); | ||||
if (!rows.length) { | ||||
|
@@ -358,9 +369,9 @@ export default class ClientApplicationsStore | |||
const environments = rows.reduce((acc, row) => { | ||||
const { | ||||
environment, | ||||
instance_id, | ||||
sdk_version, | ||||
last_seen, | ||||
unique_instance_count, | ||||
sdk_versions, | ||||
latest_last_seen, | ||||
project, | ||||
features, | ||||
strategies, | ||||
|
@@ -383,12 +394,9 @@ export default class ClientApplicationsStore | |||
if (!env) { | ||||
env = { | ||||
name: environment, | ||||
instanceCount: instance_id ? 1 : 0, | ||||
sdks: sdk_version ? [sdk_version] : [], | ||||
lastSeen: last_seen, | ||||
uniqueInstanceIds: new Set( | ||||
instance_id ? [instance_id] : [], | ||||
), | ||||
instanceCount: Number(unique_instance_count), | ||||
sdks: sdk_versions, | ||||
lastSeen: latest_last_seen, | ||||
issues: { | ||||
missingFeatures: featuresNotMappedToProject | ||||
? features | ||||
|
@@ -397,25 +405,14 @@ export default class ClientApplicationsStore | |||
}; | ||||
acc.push(env); | ||||
} else { | ||||
if (instance_id) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got rid of all of this logic done in memory |
||||
env.uniqueInstanceIds.add(instance_id); | ||||
env.instanceCount = env.uniqueInstanceIds.size; | ||||
} | ||||
if (featuresNotMappedToProject) { | ||||
env.issues.missingFeatures = features; | ||||
} | ||||
if (sdk_version && !env.sdks.includes(sdk_version)) { | ||||
env.sdks.push(sdk_version); | ||||
} | ||||
if (new Date(last_seen) > new Date(env.lastSeen)) { | ||||
env.lastSeen = last_seen; | ||||
} | ||||
} | ||||
|
||||
return acc; | ||||
}, []); | ||||
environments.forEach((env) => { | ||||
delete env.uniqueInstanceIds; | ||||
env.sdks.sort(); | ||||
}); | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra where clause to reduce query scope