From e13aa067ef8e084a3fbe91c53fafe7ab10ec1883 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 9 Jul 2021 22:27:22 +0200 Subject: [PATCH] Fix getting favorite tasks --- pkg/models/namespace.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 7c4753dca..01505cddb 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -392,12 +392,21 @@ func getFavoriteLists(s *xorm.Session, lists []*List, namespaceIDs []int64, doer } // Check if we have any favorites or favorited lists and remove the favorites namespace from the list if not - var favoriteCount int64 - favoriteCount, err = s. + cond := builder. + Select("tasks.id"). + From("tasks"). Join("INNER", "lists", "tasks.list_id = lists.id"). Join("INNER", "namespaces", "lists.namespace_id = namespaces.id"). - Where(builder.And(builder.Eq{"tasks.is_favorite": true}, builder.In("namespaces.id", namespaceIDs))). - Count(&Task{}) + Where(builder.In("namespaces.id", namespaceIDs)) + + var favoriteCount int64 + favoriteCount, err = s. + Where(builder.And( + builder.Eq{"user_id": doer.ID}, + builder.Eq{"kind": FavoriteKindTask}, + builder.In("entity_id", cond), + )). + Count(&Favorite{}) if err != nil { return } @@ -553,7 +562,7 @@ func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int ////////////////////// // Put it all together - err = addListDetails(s, lists) + err = addListDetails(s, lists, a) if err != nil { return }