diff --git a/server/datastore/mysql/labels.go b/server/datastore/mysql/labels.go index 7e32c03482..0503de3e0d 100644 --- a/server/datastore/mysql/labels.go +++ b/server/datastore/mysql/labels.go @@ -185,14 +185,13 @@ func (d *Datastore) ListUniqueHostsInLabels(labels []uint) ([]kolide.Host, error } sqlStatement := ` - SELECT h.* + SELECT DISTINCT h.* FROM label_query_executions lqe JOIN hosts h ON lqe.host_id = h.id WHERE lqe.label_id IN (?) AND lqe.matches = 1 AND NOT h.deleted - GROUP BY h.id; ` query, args, err := sqlx.In(sqlStatement, labels) if err != nil { diff --git a/server/kolide/labels.go b/server/kolide/labels.go index a581f04443..00a2727abf 100644 --- a/server/kolide/labels.go +++ b/server/kolide/labels.go @@ -29,7 +29,13 @@ type LabelStore interface { // LabelsForHost returns the labels that the given host is in. ListLabelsForHost(hid uint) ([]Label, error) + // ListHostsInLabel returns a slice of hosts in the label with the + // given ID. ListHostsInLabel(lid uint) ([]Host, error) + + // ListUniqueHostsInLabels returns a slice of all of the hosts in the + // given label IDs. A host will only appear once in the results even if + // it is in multiple of the provided labels. ListUniqueHostsInLabels(labels []uint) ([]Host, error) SearchLabels(query string, omit ...uint) ([]Label, error)