mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Fix where clause building with right hosts alias (#2875)
This commit is contained in:
parent
700d78278b
commit
b7ed3589a8
2 changed files with 3 additions and 2 deletions
|
|
@ -737,7 +737,7 @@ func (d *Datastore) SearchHosts(ctx context.Context, filter fleet.TeamFilter, qu
|
|||
}
|
||||
args = append(args, in)
|
||||
sqlb.WriteString(" id NOT IN (?) AND ")
|
||||
sqlb.WriteString(d.whereFilterHostsByTeams(filter, "hosts"))
|
||||
sqlb.WriteString(d.whereFilterHostsByTeams(filter, "h"))
|
||||
sqlb.WriteString(` ORDER BY hst.seen_time DESC LIMIT 10`)
|
||||
|
||||
sql, args, err := sqlx.In(sqlb.String(), args...)
|
||||
|
|
|
|||
|
|
@ -443,6 +443,7 @@ func (d *Datastore) ListHostsInLabel(ctx context.Context, filter fleet.TeamFilte
|
|||
return hosts, nil
|
||||
}
|
||||
|
||||
// NOTE: the hosts table must be aliased to `h` in the query passed to this function.
|
||||
func (d *Datastore) applyHostLabelFilters(filter fleet.TeamFilter, lid uint, query string, opt fleet.HostListOptions) (string, []interface{}) {
|
||||
params := []interface{}{lid}
|
||||
|
||||
|
|
@ -456,7 +457,7 @@ func (d *Datastore) applyHostLabelFilters(filter fleet.TeamFilter, lid uint, que
|
|||
}
|
||||
|
||||
func (d *Datastore) CountHostsInLabel(ctx context.Context, filter fleet.TeamFilter, lid uint, opt fleet.HostListOptions) (int, error) {
|
||||
query := `SELECT count(*) FROM label_membership lm
|
||||
query := `SELECT count(*) FROM label_membership lm
|
||||
JOIN hosts h ON (lm.host_id = h.id)
|
||||
LEFT JOIN host_seen_times hst ON (h.id=hst.host_id)
|
||||
WHERE lm.label_id = ?`
|
||||
|
|
|
|||
Loading…
Reference in a new issue