From fd3ccd6130c118eb32cf414cb42077798e9781d8 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 3 May 2020 21:28:36 +0000 Subject: [PATCH] Fix total label count when getting all labels (#477) Fix total label count when getting all labels Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/api/pulls/477 --- pkg/models/label_task.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/models/label_task.go b/pkg/models/label_task.go index f8ade2d131b..60395a7cb5e 100644 --- a/pkg/models/label_task.go +++ b/pkg/models/label_task.go @@ -209,15 +209,11 @@ func getLabelsByTaskIDs(opts *LabelByTaskIDsOptions) (ls []*labelWithTaskID, res } // Get the total number of entries - condCount := builder.And(builder.In("label_task.task_id", opts.TaskIDs), builder.NotNull{"label_task.label_id"}) - if opts.GetUnusedLabels { - condCount = builder.Or(cond, builder.Eq{"labels.created_by_id": opts.User.ID}) - } totalEntries, err = x.Table("labels"). + Select("count(DISTINCT labels.id)"). Join("LEFT", "label_task", "label_task.label_id = labels.id"). - Where(condCount). + Where(cond). And("labels.title LIKE ?", "%"+opts.Search+"%"). - GroupBy(groupBy). Count(&Label{}) if err != nil { return nil, 0, 0, err