|
|
@ -1,6 +1,7 @@
|
|
|
|
package dao
|
|
|
|
package dao
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/rocboss/paopao-ce/internal/conf"
|
|
|
|
"github.com/rocboss/paopao-ce/internal/conf"
|
|
|
@ -9,6 +10,10 @@ import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
errNotExist = errors.New("index posts cache not exist")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.PostFormated, error)) *simpleCacheIndexServant {
|
|
|
|
func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.PostFormated, error)) *simpleCacheIndexServant {
|
|
|
|
s := conf.SimpleCacheIndexSetting
|
|
|
|
s := conf.SimpleCacheIndexSetting
|
|
|
|
cacheIndex := &simpleCacheIndexServant{
|
|
|
|
cacheIndex := &simpleCacheIndexServant{
|
|
|
@ -43,15 +48,15 @@ func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.
|
|
|
|
return cacheIndex
|
|
|
|
return cacheIndex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *simpleCacheIndexServant) IndexPosts(offset int, limit int) ([]*model.PostFormated, bool) {
|
|
|
|
func (s *simpleCacheIndexServant) IndexPosts(offset int, limit int) ([]*model.PostFormated, error) {
|
|
|
|
posts := s.atomicIndex.Load().([]*model.PostFormated)
|
|
|
|
posts := s.atomicIndex.Load().([]*model.PostFormated)
|
|
|
|
end := offset + limit
|
|
|
|
end := offset + limit
|
|
|
|
size := len(posts)
|
|
|
|
size := len(posts)
|
|
|
|
logrus.Debugf("get index posts from posts: %d offset:%d limit:%d start:%d, end:%d", size, offset, limit, offset, end)
|
|
|
|
logrus.Debugf("get index posts from posts: %d offset:%d limit:%d start:%d, end:%d", size, offset, limit, offset, end)
|
|
|
|
if size >= end {
|
|
|
|
if size >= end {
|
|
|
|
return posts[offset:end], true
|
|
|
|
return posts[offset:end], nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
return nil, errNotExist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *simpleCacheIndexServant) SendAction(act core.IndexActionT) {
|
|
|
|
func (s *simpleCacheIndexServant) SendAction(act core.IndexActionT) {
|
|
|
|