From 41435a6c4ee0a5b52528890edf3fbf5a9dc0a6c8 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Sat, 4 Nov 2023 20:21:20 +0000 Subject: [feature] support canceling scheduled tasks, some federation API performance improvements (#2329) --- internal/processing/workers/fromfediapi_test.go | 50 +++++++------------------ 1 file changed, 14 insertions(+), 36 deletions(-) (limited to 'internal/processing/workers/fromfediapi_test.go') diff --git a/internal/processing/workers/fromfediapi_test.go b/internal/processing/workers/fromfediapi_test.go index f8e3941fc..b8d86ac45 100644 --- a/internal/processing/workers/fromfediapi_test.go +++ b/internal/processing/workers/fromfediapi_test.go @@ -29,7 +29,6 @@ import ( apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/id" "github.com/superseriousbusiness/gotosocial/internal/messages" "github.com/superseriousbusiness/gotosocial/internal/stream" "github.com/superseriousbusiness/gotosocial/internal/util" @@ -92,54 +91,33 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() { repliedStatus := suite.testStatuses["local_account_1_status_1"] replyingAccount := suite.testAccounts["remote_account_1"] - replyingStatus := >smodel.Status{ - CreatedAt: time.Now(), - UpdatedAt: time.Now(), - URI: "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552", - URL: "http://fossbros-anonymous.io/@foss_satan/106221634728637552", - Content: `

@the_mighty_zork nice there it is:

social.pixie.town/users/f0x/st

`, - Mentions: []*gtsmodel.Mention{ - { - TargetAccountURI: repliedAccount.URI, - NameString: "@the_mighty_zork@localhost:8080", - }, - }, - AccountID: replyingAccount.ID, - AccountURI: replyingAccount.URI, - InReplyToID: repliedStatus.ID, - InReplyToURI: repliedStatus.URI, - InReplyToAccountID: repliedAccount.ID, - Visibility: gtsmodel.VisibilityUnlocked, - ActivityStreamsType: ap.ObjectNote, - Federated: util.Ptr(true), - Boostable: util.Ptr(true), - Replyable: util.Ptr(true), - Likeable: util.Ptr(false), - } + // Set the replyingAccount's last fetched_at + // date to something recent so no refresh is attempted. + replyingAccount.FetchedAt = time.Now() + err := suite.state.DB.UpdateAccount(context.Background(), replyingAccount, "fetched_at") + suite.NoError(err) + + // Get replying statusable to use from remote test statuses. + const replyingURI = "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552" + replyingStatusable := testrig.NewTestFediStatuses()[replyingURI] + ap.AppendInReplyTo(replyingStatusable, testrig.URLMustParse(repliedStatus.URI)) + // Open a websocket stream to later test the streamed status reply. wssStream, errWithCode := suite.processor.Stream().Open(context.Background(), repliedAccount, stream.TimelineHome) suite.NoError(errWithCode) - // id the status based on the time it was created - statusID, err := id.NewULIDFromTime(replyingStatus.CreatedAt) - suite.NoError(err) - replyingStatus.ID = statusID - - err = suite.db.PutStatus(context.Background(), replyingStatus) - suite.NoError(err) - + // Send the replied status off to the fedi worker to be further processed. err = suite.processor.Workers().ProcessFromFediAPI(context.Background(), messages.FromFediAPI{ APObjectType: ap.ObjectNote, APActivityType: ap.ActivityCreate, - GTSModel: replyingStatus, + APObjectModel: replyingStatusable, ReceivingAccount: suite.testAccounts["local_account_1"], }) suite.NoError(err) // side effects should be triggered // 1. status should be in the database - suite.NotEmpty(replyingStatus.ID) - _, err = suite.db.GetStatusByID(context.Background(), replyingStatus.ID) + replyingStatus, err := suite.state.DB.GetStatusByURI(context.Background(), replyingURI) suite.NoError(err) // 2. a notification should exist for the mention -- cgit v1.2.3