From 480ce48a3efa3c06d7f60c73c002f59f7fa0ba14 Mon Sep 17 00:00:00 2001 From: tobi Date: Tue, 7 Jan 2025 17:52:28 +0100 Subject: [PATCH] make higherPrios a simple slice --- .../admin/domainpermissionsubscription.go | 11 +++++------ internal/subscriptions/domainperms.go | 16 +++------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/internal/processing/admin/domainpermissionsubscription.go b/internal/processing/admin/domainpermissionsubscription.go index 31be40a80..6c051222c 100644 --- a/internal/processing/admin/domainpermissionsubscription.go +++ b/internal/processing/admin/domainpermissionsubscription.go @@ -322,11 +322,6 @@ func(ps *gtsmodel.DomainPermissionSubscription) bool { }, ) - // Everything *before* the targeted subscription has a higher priority. - getHigherPrios := func() ([]*gtsmodel.DomainPermissionSubscription, error) { - return permSubs[:index], nil - } - // Get a transport for calling permSub.URI. tsport, err := p.transport.NewTransportForUsername(ctx, acct.Username) if err != nil { @@ -334,6 +329,10 @@ func(ps *gtsmodel.DomainPermissionSubscription) bool { return nil, gtserror.NewErrorInternalError(err) } + // Everything *before* the targeted + // subscription has a higher priority. + higherPrios := permSubs[:index] + // Call the permSub.URI and parse a list of perms from it. // Any error returned here is a "real" one, not an error // from fetching / parsing the list. @@ -341,7 +340,7 @@ func(ps *gtsmodel.DomainPermissionSubscription) bool { ctx, permSub, tsport, - getHigherPrios, + higherPrios, true, // Dry run. ) if err != nil { diff --git a/internal/subscriptions/domainperms.go b/internal/subscriptions/domainperms.go index df48fea41..75403176e 100644 --- a/internal/subscriptions/domainperms.go +++ b/internal/subscriptions/domainperms.go @@ -168,15 +168,13 @@ func (s *Subscriptions) ProcessDomainPermissionSubscriptions( for i, permSub := range permSubs { // Higher priority permission subs = everything // above this permission sub in the slice. - getHigherPrios := func() ([]*gtsmodel.DomainPermissionSubscription, error) { - return permSubs[:i], nil - } + higherPrios := permSubs[:i] _, err := s.ProcessDomainPermissionSubscription( ctx, permSub, tsport, - getHigherPrios, + higherPrios, false, // Not dry. Wet, if you will. ) if err != nil { @@ -221,7 +219,7 @@ func (s *Subscriptions) ProcessDomainPermissionSubscription( ctx context.Context, permSub *gtsmodel.DomainPermissionSubscription, tsport transport.Transport, - getHigherPrios func() ([]*gtsmodel.DomainPermissionSubscription, error), + higherPrios []*gtsmodel.DomainPermissionSubscription, dry bool, ) ([]gtsmodel.DomainPermission, error) { l := log. @@ -311,14 +309,6 @@ func (s *Subscriptions) ProcessDomainPermissionSubscription( permSub.ETag = resp.ETag permSub.Error = "" - // Need a list of higher priority subscriptions - // to ensure we don't create permissions wrongly. - higherPrios, err := getHigherPrios() - if err != nil { - // Proper db error. - return nil, err - } - // Keep track of which domain perms are // created (or would be, if dry == true). createdPerms := make([]gtsmodel.DomainPermission, 0, len(wantedPerms))