mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[chore] various federatingdb tweaks (#4178)
after seeing a potential reported federating worker lockup i decided to start digging into the federatingdb code. this PR encompasses: - removes one of our last unused interface types `federatingdb.DB{}`, replacing it with a struct type `*federatingdb.DB{}` - in `transport.dereferenceLocal()` differentiates between an unsupported lookup type and ErrNoEntries to reduce unnecessary calls, and reduce potential lockups that may occur while trying to call our own endpoints that then call `federatingdb.Lock()` - removes a bunch of the locks on follow state changes since the DB already synchronizes that - removes the unnecessary `pub.Clock{}` struct field and type passed to the transport controller frankly it would be great if we could remove the locking in `federatingdb.Lock()` and instead handle it ourselves as it gets very confusing trying to figure out what functions will have locks held. but i guess that's one for when we move further away from the go-fed/activity/pub package usage. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4178 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
@@ -20,7 +20,6 @@ package federatingdb
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"code.superseriousbusiness.org/activity/streams"
|
||||
@@ -65,16 +64,20 @@ func sameActor(actor1 vocab.ActivityStreamsActorProperty, actor2 vocab.ActivityS
|
||||
}
|
||||
|
||||
for a1Iter := actor1.Begin(); a1Iter != actor1.End(); a1Iter = a1Iter.Next() {
|
||||
a1IRI := a1Iter.GetIRI()
|
||||
if a1IRI == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
a1IRIStr := a1IRI.String()
|
||||
for a2Iter := actor2.Begin(); a2Iter != actor2.End(); a2Iter = a2Iter.Next() {
|
||||
if a1Iter.GetIRI() == nil {
|
||||
a2IRI := a2Iter.GetIRI()
|
||||
if a2IRI == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if a2Iter.GetIRI() == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if a1Iter.GetIRI().String() == a2Iter.GetIRI().String() {
|
||||
a2IRIStr := a2IRI.String()
|
||||
if a1IRIStr == a2IRIStr {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -89,7 +92,7 @@ func sameActor(actor1 vocab.ActivityStreamsActorProperty, actor2 vocab.ActivityS
|
||||
//
|
||||
// The go-fed library will handle setting the 'id' property on the
|
||||
// activity or object provided with the value returned.
|
||||
func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) {
|
||||
func (f *DB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) {
|
||||
log.DebugKV(ctx, "newID", serialize{t})
|
||||
|
||||
// Most of our types set an ID already
|
||||
@@ -116,19 +119,18 @@ func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL,
|
||||
}
|
||||
|
||||
// Default fallback behaviour:
|
||||
// {proto}://{host}/{randomID}
|
||||
newID, err := id.NewRandomULID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return url.Parse(fmt.Sprintf("%s://%s/%s", config.GetProtocol(), config.GetHost(), newID))
|
||||
// {proto}://{host}/{newULID}
|
||||
return &url.URL{
|
||||
Scheme: config.GetProtocol(),
|
||||
Host: config.GetHost(),
|
||||
Path: "/" + id.NewULID(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ActorForOutbox fetches the local actor's IRI for the given outbox IRI.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) ActorForOutbox(ctx context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
func (f *DB) ActorForOutbox(ctx context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
acct, err := f.state.DB.GetOneAccountByOutboxURI(ctx, outboxIRI.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -139,7 +141,7 @@ func (f *federatingDB) ActorForOutbox(ctx context.Context, outboxIRI *url.URL) (
|
||||
// ActorForInbox fetches the local actor's IRI for the given inbox IRI.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
func (f *DB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
acct, err := f.state.DB.GetOneAccountByInboxURI(ctx, inboxIRI.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -148,7 +150,7 @@ func (f *federatingDB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (ac
|
||||
}
|
||||
|
||||
// collectFollows takes a slice of iris and converts them into ActivityStreamsCollection of IRIs.
|
||||
func (f *federatingDB) collectIRIs(_ context.Context, iris []*url.URL) (vocab.ActivityStreamsCollection, error) {
|
||||
func (f *DB) collectIRIs(_ context.Context, iris []*url.URL) (vocab.ActivityStreamsCollection, error) {
|
||||
collection := streams.NewActivityStreamsCollection()
|
||||
items := streams.NewActivityStreamsItemsProperty()
|
||||
for _, i := range iris {
|
||||
|
Reference in New Issue
Block a user