diff --git a/internal/processing/timeline/manager.go b/internal/processing/timeline/manager.go new file mode 100644 index 0000000..e8a8262 --- /dev/null +++ b/internal/processing/timeline/manager.go @@ -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 . +*/ + +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 +} diff --git a/internal/processing/timeline/post.go b/internal/processing/timeline/post.go new file mode 100644 index 0000000..eebe9a6 --- /dev/null +++ b/internal/processing/timeline/post.go @@ -0,0 +1 @@ +package timeline \ No newline at end of file diff --git a/internal/processing/timeline/sharedpool.go b/internal/processing/timeline/sharedpool.go new file mode 100644 index 0000000..36cdf53 --- /dev/null +++ b/internal/processing/timeline/sharedpool.go @@ -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] +} diff --git a/internal/processing/timeline/timeline.go b/internal/processing/timeline/timeline.go new file mode 100644 index 0000000..10d6d3c --- /dev/null +++ b/internal/processing/timeline/timeline.go @@ -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 . +*/ + +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 +}