mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-30 00:36:14 -06:00
work on timeline fixes a little
This commit is contained in:
parent
778c8377e4
commit
ae2c2a497a
3 changed files with 142 additions and 1 deletions
|
|
@ -44,11 +44,13 @@ func (t *timeline) Get(amount int, maxID string, sinceID string, minID string) (
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// no params are defined to just fetch from the top
|
// no params are defined to just fetch from the top
|
||||||
|
// this is equivalent to a user asking for the top x posts from their timeline
|
||||||
if maxID == "" && sinceID == "" && minID == "" {
|
if maxID == "" && sinceID == "" && minID == "" {
|
||||||
statuses, err = t.GetXFromTop(amount)
|
statuses, err = t.GetXFromTop(amount)
|
||||||
// aysnchronously prepare the next predicted query so it's ready when the user asks for it
|
// aysnchronously prepare the next predicted query so it's ready when the user asks for it
|
||||||
if len(statuses) != 0 {
|
if len(statuses) != 0 {
|
||||||
nextMaxID := statuses[len(statuses)-1].ID
|
nextMaxID := statuses[len(statuses)-1].ID
|
||||||
|
// already cache the next query to speed up scrolling
|
||||||
go func() {
|
go func() {
|
||||||
if err := t.prepareNextQuery(amount, nextMaxID, "", ""); err != nil {
|
if err := t.prepareNextQuery(amount, nextMaxID, "", ""); err != nil {
|
||||||
l.Errorf("error preparing next query: %s", err)
|
l.Errorf("error preparing next query: %s", err)
|
||||||
|
|
@ -58,12 +60,14 @@ func (t *timeline) Get(amount int, maxID string, sinceID string, minID string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxID is defined but sinceID isn't so take from behind
|
// maxID is defined but sinceID isn't so take from behind
|
||||||
|
// this is equivalent to a user asking for the next x posts from their timeline, starting from maxID
|
||||||
if maxID != "" && sinceID == "" {
|
if maxID != "" && sinceID == "" {
|
||||||
attempts := 0
|
attempts := 0
|
||||||
statuses, err = t.GetXBehindID(amount, maxID, &attempts)
|
statuses, err = t.GetXBehindID(amount, maxID, &attempts)
|
||||||
// aysnchronously prepare the next predicted query so it's ready when the user asks for it
|
// aysnchronously prepare the next predicted query so it's ready when the user asks for it
|
||||||
if len(statuses) != 0 {
|
if len(statuses) != 0 {
|
||||||
nextMaxID := statuses[len(statuses)-1].ID
|
nextMaxID := statuses[len(statuses)-1].ID
|
||||||
|
// already cache the next query to speed up scrolling
|
||||||
go func() {
|
go func() {
|
||||||
if err := t.prepareNextQuery(amount, nextMaxID, "", ""); err != nil {
|
if err := t.prepareNextQuery(amount, nextMaxID, "", ""); err != nil {
|
||||||
l.Errorf("error preparing next query: %s", err)
|
l.Errorf("error preparing next query: %s", err)
|
||||||
|
|
@ -73,6 +77,7 @@ func (t *timeline) Get(amount int, maxID string, sinceID string, minID string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxID is defined and sinceID || minID are as well, so take a slice between them
|
// maxID is defined and sinceID || minID are as well, so take a slice between them
|
||||||
|
// this is equivalent to a user asking for posts older than x but newer than y
|
||||||
if maxID != "" && sinceID != "" {
|
if maxID != "" && sinceID != "" {
|
||||||
statuses, err = t.GetXBetweenID(amount, maxID, minID)
|
statuses, err = t.GetXBetweenID(amount, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
@ -81,6 +86,7 @@ func (t *timeline) Get(amount int, maxID string, sinceID string, minID string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxID isn't defined, but sinceID || minID are, so take x before
|
// maxID isn't defined, but sinceID || minID are, so take x before
|
||||||
|
// this is equivalent to a user asking for posts newer than x (eg., refreshing the top of their timeline)
|
||||||
if maxID == "" && sinceID != "" {
|
if maxID == "" && sinceID != "" {
|
||||||
statuses, err = t.GetXBeforeID(amount, sinceID, true)
|
statuses, err = t.GetXBeforeID(amount, sinceID, true)
|
||||||
}
|
}
|
||||||
|
|
@ -147,13 +153,15 @@ findMarkLoop:
|
||||||
return nil, errors.New("GetXBehindID: could not parse e as a preparedPostsEntry")
|
return nil, errors.New("GetXBehindID: could not parse e as a preparedPostsEntry")
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.statusID == behindID {
|
if entry.statusID <= behindID {
|
||||||
behindIDMark = e
|
behindIDMark = e
|
||||||
|
} else {
|
||||||
break findMarkLoop
|
break findMarkLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we didn't find it, so we need to make sure it's indexed and prepared and then try again
|
// we didn't find it, so we need to make sure it's indexed and prepared and then try again
|
||||||
|
// this can happen when a user asks for really old posts
|
||||||
if behindIDMark == nil {
|
if behindIDMark == nil {
|
||||||
if err := t.IndexBehind(behindID, amount); err != nil {
|
if err := t.IndexBehind(behindID, amount); err != nil {
|
||||||
return nil, fmt.Errorf("GetXBehindID: error indexing behind and including ID %s", behindID)
|
return nil, fmt.Errorf("GetXBehindID: error indexing behind and including ID %s", behindID)
|
||||||
|
|
@ -225,6 +233,10 @@ findMarkLoop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if beforeIDMark == nil {
|
||||||
|
return statuses, nil
|
||||||
|
}
|
||||||
|
|
||||||
var served int
|
var served int
|
||||||
|
|
||||||
if startFromTop {
|
if startFromTop {
|
||||||
|
|
|
||||||
87
internal/timeline/get_test.go
Normal file
87
internal/timeline/get_test.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_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetTestSuite struct {
|
||||||
|
TimelineStandardTestSuite
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *GetTestSuite) SetupSuite() {
|
||||||
|
suite.testAccounts = testrig.NewTestAccounts()
|
||||||
|
suite.testStatuses = testrig.NewTestStatuses()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *GetTestSuite) SetupTest() {
|
||||||
|
suite.config = testrig.NewTestConfig()
|
||||||
|
suite.db = testrig.NewTestDB()
|
||||||
|
suite.log = testrig.NewTestLog()
|
||||||
|
suite.tc = testrig.NewTestTypeConverter(suite.db)
|
||||||
|
|
||||||
|
testrig.StandardDBSetup(suite.db, nil)
|
||||||
|
|
||||||
|
// let's take local_account_1 as the timeline owner
|
||||||
|
tl, err := timeline.NewTimeline(suite.testAccounts["local_account_1"].ID, suite.db, suite.tc, suite.log)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare the timeline by just shoving all test statuses in it -- let's not be fussy about who sees what
|
||||||
|
for _, s := range suite.testStatuses {
|
||||||
|
_, err := tl.IndexAndPrepareOne(s.CreatedAt, s.ID, s.BoostOfID, s.AccountID, s.BoostOfAccountID)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suite.timeline = tl
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *GetTestSuite) TearDownTest() {
|
||||||
|
testrig.StandardDBTeardown(suite.db)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *GetTestSuite) TestGet() {
|
||||||
|
// get 10 from the top
|
||||||
|
statuses, err := suite.timeline.Get(10, "", "", "")
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(len(statuses))
|
||||||
|
fmt.Println(len(statuses))
|
||||||
|
fmt.Println(len(statuses))
|
||||||
|
fmt.Println(len(statuses))
|
||||||
|
fmt.Println(len(statuses))
|
||||||
|
fmt.Println(len(statuses))
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(GetTestSuite))
|
||||||
|
}
|
||||||
42
internal/timeline/timeline_test.go
Normal file
42
internal/timeline/timeline_test.go
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
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_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TimelineStandardTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
config *config.Config
|
||||||
|
db db.DB
|
||||||
|
log *logrus.Logger
|
||||||
|
tc typeutils.TypeConverter
|
||||||
|
|
||||||
|
testAccounts map[string]*gtsmodel.Account
|
||||||
|
testStatuses map[string]*gtsmodel.Status
|
||||||
|
|
||||||
|
timeline timeline.Timeline
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue