Merge pull request #80 from alimy/pr-cache

fixed cache index calculate offset/limit error
pull/82/head
Michael Li 2 years ago committed by GitHub
commit 804cc7b7a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,11 +29,11 @@ func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.
func (s *simpleCacheIndexServant) IndexPosts(offset int, limit int) ([]*model.PostFormated, bool) { func (s *simpleCacheIndexServant) IndexPosts(offset int, limit int) ([]*model.PostFormated, bool) {
posts := s.atomicIndex.Load().([]*model.PostFormated) posts := s.atomicIndex.Load().([]*model.PostFormated)
start := offset * limit end := offset + limit
end := start + limit size := len(posts)
if len(posts) >= end { logrus.Debugf("get index posts from posts: %d offset:%d limit:%d start:%d, end:%d", size, offset, limit, offset, end)
logrus.Debugln("get index posts from cached") if size >= end {
return posts[start:end], true return posts[offset:end], true
} }
return nil, false return nil, false
} }

Loading…
Cancel
Save