diff --git a/app/store/bolt.go b/app/store/bolt.go index b1782a49..f7773cf3 100644 --- a/app/store/bolt.go +++ b/app/store/bolt.go @@ -550,7 +550,7 @@ func (b *BoltDB) count(tx *bolt.Tx, postURL string, val int) (int, error) { if countVal == nil { countVal = itob(0) } - if val == 0 { + if val == 0 { // get current count, don't update return btoi(countVal), nil } updatedCount := btoi(countVal) + val diff --git a/app/store/service.go b/app/store/service.go index 0a23a602..c563da1a 100644 --- a/app/store/service.go +++ b/app/store/service.go @@ -81,18 +81,11 @@ func (s *Service) EditComment(locator Locator, commentID string, text string, ed } // Counts returns postID+count list for given comments -func (s *Service) Counts(siteID string, commentIDs []string) ([]PostInfo, error) { - list, err := s.List(siteID, 0, 0) - if err != nil { - return nil, err - } - +func (s *Service) Counts(siteID string, postIDs []string) ([]PostInfo, error) { res := []PostInfo{} - for _, p := range commentIDs { - for _, l := range list { - if p == l.URL { - res = append(res, l) - } + for _, p := range postIDs { + if c, err := s.Count(Locator{SiteID: siteID, URL: p}); err == nil { + res = append(res, PostInfo{URL: p, Count: c}) } } return res, nil diff --git a/app/store/service_test.go b/app/store/service_test.go index b6111592..61651611 100644 --- a/app/store/service_test.go +++ b/app/store/service_test.go @@ -143,5 +143,6 @@ func TestService_Counts(t *testing.T) { assert.Equal(t, []PostInfo{ PostInfo{URL: "https://radio-t.com", Count: 2}, PostInfo{URL: "https://radio-t.com/2", Count: 1}, + PostInfo{URL: "blah", Count: 0}, }, res) }