[feature] add per-uri dereferencer locks (#2291)

This commit is contained in:
kim 2023-10-31 11:12:22 +00:00 committed by GitHub
commit ce71a5a790
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 2432 additions and 2719 deletions

View file

@ -20,7 +20,6 @@ package federatingdb
import (
"context"
"codeberg.org/gruf/go-mutexes"
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/state"
@ -40,7 +39,6 @@ type DB interface {
// FederatingDB uses the underlying DB interface to implement the go-fed pub.Database interface.
// It doesn't care what the underlying implementation of the DB interface is, as long as it works.
type federatingDB struct {
locks mutexes.MutexMap
state *state.State
converter *typeutils.Converter
}
@ -48,7 +46,6 @@ type federatingDB struct {
// New returns a DB interface using the given database and config
func New(state *state.State, converter *typeutils.Converter) DB {
fdb := federatingDB{
locks: mutexes.NewMap(-1, -1), // use defaults
state: state,
converter: converter,
}

View file

@ -19,7 +19,6 @@ package federatingdb
import (
"context"
"errors"
"net/url"
)
@ -35,9 +34,5 @@ import (
//
// Used to ensure race conditions in multiple requests do not occur.
func (f *federatingDB) Lock(c context.Context, id *url.URL) (func(), error) {
if id == nil {
return nil, errors.New("Lock: id was nil")
}
unlock := f.locks.Lock(id.String())
return unlock, nil
return f.state.FedLocks.Lock("federatingDB " + id.String()), nil // id should NEVER be nil.
}