From 71a384f34a30ceed50e38ced8b5eb23243ae643d Mon Sep 17 00:00:00 2001 From: Zachary Wasserman Date: Thu, 2 Mar 2017 15:40:50 -0800 Subject: [PATCH] Show built in labels first in targets selector (#1338) --- server/datastore/mysql/labels.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/datastore/mysql/labels.go b/server/datastore/mysql/labels.go index d78ed029c2..9a3b61c092 100644 --- a/server/datastore/mysql/labels.go +++ b/server/datastore/mysql/labels.go @@ -241,7 +241,7 @@ func (d *Datastore) searchLabelsWithOmits(query string, omit ...uint) ([]kolide. AND NOT deleted ) AND id NOT IN (?) - ORDER BY id ASC + ORDER BY label_type DESC, id ASC LIMIT 10 ` @@ -306,6 +306,7 @@ func (d *Datastore) searchLabelsDefault(omit ...uint) ([]kolide.Label, error) { FROM labels WHERE NOT deleted AND id NOT IN (?) + ORDER BY label_type DESC, id ASC LIMIT 5 ` @@ -349,6 +350,10 @@ func (d *Datastore) SearchLabels(query string, omit ...uint) ([]kolide.Label, er query += "*" + // Ordering first by label_type ensures that built-in labels come + // first. We will probably need to make a custom ordering function here + // if additional label types are added. Ordering next by ID ensures + // that the order is always consistent. sqlStatement := ` SELECT * FROM labels @@ -356,7 +361,7 @@ func (d *Datastore) SearchLabels(query string, omit ...uint) ([]kolide.Label, er MATCH(name) AGAINST(? IN BOOLEAN MODE) AND NOT deleted ) - ORDER BY id ASC + ORDER BY label_type DESC, id ASC LIMIT 10 ` matches := []kolide.Label{}