mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 01:18:42 +00:00
Make software filter by counts faster (#3975)
* Make software filter by counts faster * Sort only when it's for the agg table
This commit is contained in:
parent
a5b2e60075
commit
a63c549f07
1 changed files with 17 additions and 2 deletions
|
|
@ -314,12 +314,27 @@ func selectSoftwareSQL(hostID *uint, opts fleet.SoftwareListOptions) (string, []
|
|||
}
|
||||
|
||||
if opts.WithHostCounts {
|
||||
subSelectCounts := dialect.From(goqu.I("aggregated_stats").As("shc")).Select(
|
||||
"shc.id", "shc.json_value", "shc.updated_at",
|
||||
).Where(goqu.I("shc.type").Eq("software_hosts_count"), goqu.I("shc.json_value").Gt(0)).
|
||||
SelectAppend(
|
||||
goqu.I("shc.json_value").As("hosts_count"),
|
||||
goqu.I("shc.updated_at").As("counts_updated_at"),
|
||||
)
|
||||
subSelectListOpts := opts.ListOptions
|
||||
switch subSelectListOpts.OrderKey {
|
||||
case "hosts_counts", "counts_updated_at":
|
||||
// all good, known columns, so we sort
|
||||
subSelectCounts = appendListOptionsToSelect(subSelectCounts, opts.ListOptions)
|
||||
default:
|
||||
// we don't sort if it's not a column from this table
|
||||
}
|
||||
ds = ds.Join(
|
||||
goqu.I("aggregated_stats").As("shc"),
|
||||
subSelectCounts.As("shc"),
|
||||
goqu.On(
|
||||
goqu.I("s.id").Eq(goqu.I("shc.id")),
|
||||
),
|
||||
).Where(goqu.I("shc.type").Eq("software_hosts_count"), goqu.I("shc.json_value").Gt(0)).
|
||||
).
|
||||
SelectAppend(
|
||||
goqu.I("shc.json_value").As("hosts_count"),
|
||||
goqu.I("shc.updated_at").As("counts_updated_at"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue