|
|
@ -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
|
|
|
|
}
|
|
|
|
}
|
|
|
|