reduce number of inbox forwarding create calls by partially implementing Exists()

This commit is contained in:
kim 2025-01-15 16:02:18 +00:00
commit 3aa9abe5f3
3 changed files with 4 additions and 4 deletions

View file

@ -65,7 +65,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
// Cache entry for this create activity ID for later
// checks in the Exist() function if we see it again.
f.createdIDs.Set(ap.GetJSONLDId(asType).String(), struct{}{})
f.activityIDs.Set(ap.GetJSONLDId(asType).String(), struct{}{})
switch name := asType.GetTypeName(); name {
case ap.ActivityBlock:

View file

@ -65,7 +65,7 @@ type federatingDB struct {
// tracks Activity IDs we have handled creates for,
// for use in the Exists() function during forwarding.
createdIDs simple.Cache[string, struct{}]
activityIDs simple.Cache[string, struct{}]
}
// New returns a DB that satisfies the pub.Database
@ -84,6 +84,6 @@ func New(
intFilter: intFilter,
spamFilter: spamFilter,
}
fdb.createdIDs.Init(0, 1000)
fdb.activityIDs.Init(0, 1000)
return &fdb
}

View file

@ -25,5 +25,5 @@ import (
// 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 f.createdIDs.Has(id.String()), nil
return f.activityIDs.Has(id.String()), nil
}