summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/util.go
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-05-15 09:40:48 +0000
committerLibravatar kim <gruf@noreply.codeberg.org>2025-05-15 09:40:48 +0000
commit3cff4b2d7d138f45787a94e6e64acdccb00e8951 (patch)
treed18f18289b3082b129d6e129aa383ddde5869521 /internal/federation/federatingdb/util.go
parent[chore] Change default database in example config to sqlite, update docs. (#4... (diff)
downloadgotosocial-3cff4b2d7d138f45787a94e6e64acdccb00e8951.tar.xz
[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>
Diffstat (limited to 'internal/federation/federatingdb/util.go')
-rw-r--r--internal/federation/federatingdb/util.go38
1 files changed, 20 insertions, 18 deletions
diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go
index 32aec51a5..f235e729e 100644
--- a/internal/federation/federatingdb/util.go
+++ b/internal/federation/federatingdb/util.go
@@ -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() {
- for a2Iter := actor2.Begin(); a2Iter != actor2.End(); a2Iter = a2Iter.Next() {
- if a1Iter.GetIRI() == nil {
- return false
- }
+ a1IRI := a1Iter.GetIRI()
+ if a1IRI == nil {
+ return false
+ }
- if a2Iter.GetIRI() == nil {
+ a1IRIStr := a1IRI.String()
+ for a2Iter := actor2.Begin(); a2Iter != actor2.End(); a2Iter = a2Iter.Next() {
+ a2IRI := a2Iter.GetIRI()
+ if a2IRI == 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 {