Add context to acl tree
This commit is contained in:
parent
883e51c84d
commit
49a9edfe6c
@ -1,6 +1,7 @@
|
||||
package acltree
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage"
|
||||
"sync"
|
||||
@ -28,8 +29,8 @@ type TreeUpdateListener interface {
|
||||
|
||||
type ACLTree interface {
|
||||
ACLState() *ACLState
|
||||
AddContent(f func(builder ChangeBuilder) error) (*Change, error)
|
||||
AddChanges(changes ...*Change) (AddResult, error)
|
||||
AddContent(ctx context.Context, f func(builder ChangeBuilder) error) (*Change, error)
|
||||
AddChanges(ctx context.Context, changes ...*Change) (AddResult, error)
|
||||
Heads() []string
|
||||
Root() *Change
|
||||
Iterate(func(change *Change) bool)
|
||||
@ -197,7 +198,7 @@ func (a *aclTree) ACLState() *ACLState {
|
||||
return a.aclState
|
||||
}
|
||||
|
||||
func (a *aclTree) AddContent(build func(builder ChangeBuilder) error) (*Change, error) {
|
||||
func (a *aclTree) AddContent(ctx context.Context, build func(builder ChangeBuilder) error) (*Change, error) {
|
||||
// TODO: add snapshot creation logic
|
||||
a.Lock()
|
||||
defer func() {
|
||||
@ -234,7 +235,7 @@ func (a *aclTree) AddContent(build func(builder ChangeBuilder) error) (*Change,
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (a *aclTree) AddChanges(changes ...*Change) (AddResult, error) {
|
||||
func (a *aclTree) AddChanges(ctx context.Context, changes ...*Change) (AddResult, error) {
|
||||
a.Lock()
|
||||
// TODO: make proper error handling, because there are a lot of corner cases where this will break
|
||||
var err error
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package acltree
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/treestoragebuilder"
|
||||
@ -78,7 +79,7 @@ func TestACLTree_UserJoinUpdate_Append(t *testing.T) {
|
||||
changes = append(changes, newCh)
|
||||
}
|
||||
|
||||
res, err := tree.AddChanges(changes...)
|
||||
res, err := tree.AddChanges(context.Background(), changes...)
|
||||
assert.Equal(t, res.Summary, AddResultSummaryAppend)
|
||||
|
||||
aclState := tree.ACLState()
|
||||
@ -128,7 +129,7 @@ func TestACLTree_UserJoinUpdate_Rebuild(t *testing.T) {
|
||||
changes = append(changes, newCh)
|
||||
}
|
||||
|
||||
res, err := tree.AddChanges(changes...)
|
||||
res, err := tree.AddChanges(context.Background(), changes...)
|
||||
assert.Equal(t, res.Summary, AddResultSummaryRebuild)
|
||||
|
||||
aclState := tree.ACLState()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package plaintextdocument
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||
aclpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/pb"
|
||||
@ -13,7 +14,7 @@ import (
|
||||
|
||||
type PlainTextDocument interface {
|
||||
Text() string
|
||||
AddText(text string) error
|
||||
AddText(ctx context.Context, text string) error
|
||||
}
|
||||
|
||||
type plainTextDocument struct {
|
||||
@ -29,8 +30,8 @@ func (p *plainTextDocument) Text() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *plainTextDocument) AddText(text string) error {
|
||||
_, err := p.aclTree.AddContent(func(builder acltree.ChangeBuilder) error {
|
||||
func (p *plainTextDocument) AddText(ctx context.Context, text string) error {
|
||||
_, err := p.aclTree.AddContent(ctx, func(builder acltree.ChangeBuilder) error {
|
||||
builder.AddChangeContent(
|
||||
&pb.PlainTextChangeData{
|
||||
Content: []*pb.PlainTextChangeContent{
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package plaintextdocument
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/treestoragebuilder"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage"
|
||||
@ -43,13 +44,13 @@ func TestDocument_PlainTextDocument_AddText(t *testing.T) {
|
||||
t.Fatalf("should not create document with error: %v", err)
|
||||
}
|
||||
|
||||
err = doc.AddText("Next")
|
||||
err = doc.AddText(context.Background(), "Next")
|
||||
if err != nil {
|
||||
t.Fatalf("should be able to add document: %v", err)
|
||||
}
|
||||
assert.Equal(t, doc.Text(), "Some text|Next")
|
||||
|
||||
err = doc.AddText("Shmext")
|
||||
err = doc.AddText(context.Background(), "Shmext")
|
||||
if err != nil {
|
||||
t.Fatalf("should be able to add document: %v", err)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user