From b3c4cc4bfc6900a1e9a0c1080fe571a206eb6224 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 20 Apr 2019 11:53:23 +1000 Subject: [PATCH] Fixed a bug where it would load too many forums for non-superadmins when the topic list is filtered. --- common/topic_list.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/topic_list.go b/common/topic_list.go index 99f272fa..d6d766e8 100644 --- a/common/topic_list.go +++ b/common/topic_list.go @@ -1,6 +1,7 @@ package common import ( + //"log" "strconv" "sync" @@ -179,14 +180,14 @@ func (tList *DefaultTopicList) GetListByCanSee(canSee []int, page int, orderby s } // ? - Should we be showing plugin_guilds posts on /topics/? - argList, qlist := ForumListToArgQ(forumList) + argList, qlist := ForumListToArgQ(filteredForums) if qlist == "" { // We don't want to kill the page, so pass an empty slice and nil error - return topicList, forumList, Paginator{[]int{}, 1, 1}, nil + return topicList, filteredForums, Paginator{[]int{}, 1, 1}, nil } topicList, paginator, err = tList.getList(page, orderby, argList, qlist) - return topicList, forumList, paginator, err + return topicList, filteredForums, paginator, err } // TODO: Reduce the number of returns @@ -241,6 +242,9 @@ func (tList *DefaultTopicList) GetList(page int, orderby string, filterIDs []int // TODO: Rename this to TopicListStore and pass back a TopicList instance holding the pagination data and topic list rather than passing them back one argument at a time func (tList *DefaultTopicList) getList(page int, orderby string, argList []interface{}, qlist string) (topicList []*TopicsRow, paginator Paginator, err error) { + //log.Printf("argList: %+v\n",argList) + //log.Printf("qlist: %+v\n",qlist) + topicCount, err := ArgQToTopicCount(argList, qlist) if err != nil { return nil, Paginator{nil, 1, 1}, err @@ -338,6 +342,7 @@ func ForumListToArgQ(forums []Forum) (argList []interface{}, qlist string) { } // Internal. Don't rely on it. +// TODO: Check the TopicCount field on the forums instead? Make sure it's in sync first. func ArgQToTopicCount(argList []interface{}, qlist string) (topicCount int, err error) { topicCountStmt, err := qgen.Builder.SimpleCount("topics", "parentID IN("+qlist+")", "") if err != nil {