optimize counts go get them directly
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+4
-11
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user