little fixes, add some more test models

This commit is contained in:
tsmethurst 2021-06-21 12:21:48 +02:00
commit 4f4e86425c
5 changed files with 153 additions and 6 deletions

View file

@ -1,6 +1,7 @@
package timeline
import (
"container/list"
"errors"
"fmt"
@ -31,6 +32,17 @@ func (t *timeline) PrepareBehind(statusID string, amount int) error {
t.Lock()
defer t.Unlock()
// lazily initialize prepared posts if it hasn't been done already
if t.preparedPosts.data == nil {
t.preparedPosts.data = &list.List{}
t.preparedPosts.data.Init()
}
// if the postindex is nil, nothing has been indexed yet so there's nothing to prepare
if t.postIndex.data == nil {
return nil
}
var prepared int
var preparing bool
prepareloop:
@ -72,6 +84,17 @@ func (t *timeline) PrepareBefore(statusID string, include bool, amount int) erro
t.Lock()
defer t.Unlock()
// lazily initialize prepared posts if it hasn't been done already
if t.preparedPosts.data == nil {
t.preparedPosts.data = &list.List{}
t.preparedPosts.data.Init()
}
// if the postindex is nil, nothing has been indexed yet so there's nothing to prepare
if t.postIndex.data == nil {
return nil
}
var prepared int
var preparing bool
prepareloop:
@ -116,11 +139,24 @@ func (t *timeline) PrepareFromTop(amount int) error {
t.Lock()
defer t.Unlock()
t.preparedPosts.data.Init()
// lazily initialize prepared posts if it hasn't been done already
if t.preparedPosts.data == nil {
t.preparedPosts.data = &list.List{}
t.preparedPosts.data.Init()
}
// if the postindex is nil, nothing has been indexed yet so there's nothing to prepare
if t.postIndex.data == nil {
return nil
}
var prepared int
prepareloop:
for e := t.postIndex.data.Front(); e != nil; e = e.Next() {
if e == nil {
continue
}
entry, ok := e.Value.(*postIndexEntry)
if !ok {
return errors.New("PrepareFromTop: could not parse e as a postIndexEntry")