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) {
posts := s.atomicIndex.Load().([]*model.PostFormated)
start := offset * limit
end := start + limit
if len(posts) >= end {
logrus.Debugln("get index posts from cached")
return posts[start:end], true
end := offset + limit
size := len(posts)
logrus.Debugf("get index posts from posts: %d offset:%d limit:%d start:%d, end:%d", size, offset, limit, offset, end)
if size >= end {
return posts[offset:end], true
}
return nil, false
}

Loading…
Cancel
Save