mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-01 03:32:26 -05:00
start messing about with timeline manager
This commit is contained in:
parent
6ac6f8d614
commit
34915b3e66
4 changed files with 187 additions and 0 deletions
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]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue