summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation/federatingdb')
-rw-r--r--internal/federation/federatingdb/create.go4
-rw-r--r--internal/federation/federatingdb/db.go6
-rw-r--r--internal/federation/federatingdb/exists.go10
3 files changed, 13 insertions, 7 deletions
diff --git a/internal/federation/federatingdb/create.go b/internal/federation/federatingdb/create.go
index 60232efe3..11030b16b 100644
--- a/internal/federation/federatingdb/create.go
+++ b/internal/federation/federatingdb/create.go
@@ -63,6 +63,10 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
return nil
}
+ // Cache entry for this create activity ID for later
+ // checks in the Exist() function if we see it again.
+ f.activityIDs.Set(ap.GetJSONLDId(asType).String(), struct{}{})
+
switch name := asType.GetTypeName(); name {
case ap.ActivityBlock:
// BLOCK SOMETHING
diff --git a/internal/federation/federatingdb/db.go b/internal/federation/federatingdb/db.go
index ba10ed98b..230098073 100644
--- a/internal/federation/federatingdb/db.go
+++ b/internal/federation/federatingdb/db.go
@@ -21,6 +21,7 @@ import (
"context"
"net/url"
+ "codeberg.org/gruf/go-cache/v3/simple"
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/filter/interaction"
@@ -61,6 +62,10 @@ type federatingDB struct {
visFilter *visibility.Filter
intFilter *interaction.Filter
spamFilter *spam.Filter
+
+ // tracks Activity IDs we have handled creates for,
+ // for use in the Exists() function during forwarding.
+ activityIDs simple.Cache[string, struct{}]
}
// New returns a DB that satisfies the pub.Database
@@ -79,5 +84,6 @@ func New(
intFilter: intFilter,
spamFilter: spamFilter,
}
+ fdb.activityIDs.Init(0, 2048)
return &fdb
}
diff --git a/internal/federation/federatingdb/exists.go b/internal/federation/federatingdb/exists.go
index abac9960e..ec996f72f 100644
--- a/internal/federation/federatingdb/exists.go
+++ b/internal/federation/federatingdb/exists.go
@@ -22,12 +22,8 @@ import (
"net/url"
)
-// Exists returns true if the database has an entry for the specified
-// id. It may not be owned by this application instance.
-//
-// The library makes this call only after acquiring a lock first.
-//
-// Implementation note: this just straight up isn't implemented, and doesn't *really* need to be either.
+// Exists is an implementation of pub.Database{}.Exists(), optimized specifically for
+// the only usecase in which go-fed/activity/pub actually calls it. Do not use otherwise!
func (f *federatingDB) Exists(ctx context.Context, id *url.URL) (exists bool, err error) {
- return false, nil
+ return f.activityIDs.Has(id.String()), nil
}