start messing about with timeline manager
This commit is contained in:
parent
6ac6f8d614
commit
34915b3e66
53
internal/processing/timeline/manager.go
Normal file
53
internal/processing/timeline/manager.go
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
GoToSocial
|
||||
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package timeline
|
||||
|
||||
import (
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
type Manager interface {
|
||||
Ingest(status *gtsmodel.Status) error
|
||||
HomeTimelineGet(account *gtsmodel.Account, maxID string, sinceID string, minID string, limit int, local bool) ([]apimodel.Status, error)
|
||||
}
|
||||
|
||||
func NewManager(db db.DB, config *config.Config) Manager {
|
||||
return &manager{
|
||||
accountTimelines: make(map[string]*timeline),
|
||||
db: db,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
accountTimelines map[string]*timeline
|
||||
db db.DB
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
func (m *manager) Ingest(status *gtsmodel.Status) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) HomeTimelineGet(account *gtsmodel.Account, maxID string, sinceID string, minID string, limit int, local bool) ([]apimodel.Status, error) {
|
||||
return nil, nil
|
||||
}
|
1
internal/processing/timeline/post.go
Normal file
1
internal/processing/timeline/post.go
Normal file
@ -0,0 +1 @@
|
||||
package timeline
|
46
internal/processing/timeline/sharedpool.go
Normal file
46
internal/processing/timeline/sharedpool.go
Normal file
@ -0,0 +1,46 @@
|
||||
package timeline
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type sharedCache struct {
|
||||
data map[string]*post
|
||||
maxLength int
|
||||
*sync.Mutex
|
||||
}
|
||||
|
||||
func newSharedCache(maxLength int) *sharedCache {
|
||||
return &sharedCache{
|
||||
data: make(map[string]*post),
|
||||
maxLength: maxLength,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *sharedCache) shrink() {
|
||||
toRemove := len(s.data) - s.maxLength
|
||||
if toRemove > 0 {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
oldest := time.Now()
|
||||
oldestIDs := make([]string, toRemove)
|
||||
for id, post := range s.data {
|
||||
if post.createdAt.Before(oldest) {
|
||||
oldest = post.createdAt
|
||||
oldestIDs = append(oldestIDs, id)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (s *sharedCache) put(post *post) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
s.data[post.statusID] = post
|
||||
}
|
||||
|
||||
func (s *sharedCache) get(statusID string) *post {
|
||||
return s.data[statusID]
|
||||
}
|
87
internal/processing/timeline/timeline.go
Normal file
87
internal/processing/timeline/timeline.go
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
GoToSocial
|
||||
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package timeline
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
)
|
||||
|
||||
type timeline struct {
|
||||
index *list.List
|
||||
readyToGo []*apimodel.Status
|
||||
sharedCache *list.List
|
||||
accountID string
|
||||
db db.DB
|
||||
*sync.Mutex
|
||||
}
|
||||
|
||||
func newTimeline(accountID string, db db.DB) *timeline {
|
||||
return &timeline{
|
||||
index: list.New(),
|
||||
readyToGo: []*apimodel.Status{},
|
||||
accountID: accountID,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *timeline) prepareXFromID(limit int, statusID string) error {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *timeline) getX(limit int) (*apimodel.Status, error) {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (t *timeline) insert(status *apimodel.Status) error {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
newPost := &post{}
|
||||
|
||||
if t.index == nil {
|
||||
t.index.PushFront(newPost)
|
||||
}
|
||||
|
||||
for e := t.index.Front(); e != nil; e = e.Next() {
|
||||
p, ok := e.Value.(*post)
|
||||
if !ok {
|
||||
return errors.New("could not convert interface to post")
|
||||
}
|
||||
if p.createdAt.Before(newPost.createdAt) {
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type post struct {
|
||||
createdAt time.Time
|
||||
statusID string
|
||||
serialized *apimodel.Status
|
||||
}
|
Loading…
Reference in New Issue
Block a user