Remove last thread ids
This commit is contained in:
parent
59977218e2
commit
acff22a19e
@ -40,7 +40,7 @@ type ACLTree interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type aclTree struct {
|
type aclTree struct {
|
||||||
thread treestorage.TreeStorage
|
treeStorage treestorage.TreeStorage
|
||||||
accountData *account.AccountData
|
accountData *account.AccountData
|
||||||
updateListener TreeUpdateListener
|
updateListener TreeUpdateListener
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ func BuildACLTree(
|
|||||||
changeBuilder := newChangeBuilder()
|
changeBuilder := newChangeBuilder()
|
||||||
|
|
||||||
aclTree := &aclTree{
|
aclTree := &aclTree{
|
||||||
thread: t,
|
treeStorage: t,
|
||||||
accountData: acc,
|
accountData: acc,
|
||||||
fullTree: nil,
|
fullTree: nil,
|
||||||
aclState: nil,
|
aclState: nil,
|
||||||
@ -80,7 +80,7 @@ func BuildACLTree(
|
|||||||
changeBuilder: changeBuilder,
|
changeBuilder: changeBuilder,
|
||||||
updateListener: listener,
|
updateListener: listener,
|
||||||
}
|
}
|
||||||
err := aclTree.rebuildFromThread(false)
|
err := aclTree.rebuildFromStorage(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ func BuildACLTree(
|
|||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
// if !valid {
|
// if !valid {
|
||||||
// return a.rebuildFromThread(true)
|
// return a.rebuildFromStorage(true)
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
@ -125,7 +125,7 @@ func (a *aclTree) removeOrphans() {
|
|||||||
// removing attached or invalid orphans
|
// removing attached or invalid orphans
|
||||||
var toRemove []string
|
var toRemove []string
|
||||||
|
|
||||||
for _, orphan := range a.thread.Orphans() {
|
for _, orphan := range a.treeStorage.Orphans() {
|
||||||
if _, exists := a.fullTree.attached[orphan]; exists {
|
if _, exists := a.fullTree.attached[orphan]; exists {
|
||||||
toRemove = append(toRemove, orphan)
|
toRemove = append(toRemove, orphan)
|
||||||
}
|
}
|
||||||
@ -133,10 +133,10 @@ func (a *aclTree) removeOrphans() {
|
|||||||
toRemove = append(toRemove, orphan)
|
toRemove = append(toRemove, orphan)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a.thread.RemoveOrphans(toRemove...)
|
a.treeStorage.RemoveOrphans(toRemove...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclTree) rebuildFromThread(fromStart bool) error {
|
func (a *aclTree) rebuildFromStorage(fromStart bool) error {
|
||||||
a.treeBuilder.Init()
|
a.treeBuilder.Init()
|
||||||
a.aclTreeBuilder.Init()
|
a.aclTreeBuilder.Init()
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func (a *aclTree) rebuildFromThread(fromStart bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !valid {
|
if !valid {
|
||||||
return a.rebuildFromThread(true)
|
return a.rebuildFromStorage(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: there is a question how we can validate not only that the full tree is built correctly
|
// TODO: there is a question how we can validate not only that the full tree is built correctly
|
||||||
@ -210,7 +210,7 @@ func (a *aclTree) AddContent(build func(builder ChangeBuilder) error) (*Change,
|
|||||||
}
|
}
|
||||||
a.fullTree.AddFast(ch)
|
a.fullTree.AddFast(ch)
|
||||||
|
|
||||||
err = a.thread.AddRawChange(&treestorage.RawChange{
|
err = a.treeStorage.AddRawChange(&treestorage.RawChange{
|
||||||
Payload: marshalled,
|
Payload: marshalled,
|
||||||
Signature: ch.Signature(),
|
Signature: ch.Signature(),
|
||||||
Id: ch.Id,
|
Id: ch.Id,
|
||||||
@ -219,7 +219,7 @@ func (a *aclTree) AddContent(build func(builder ChangeBuilder) error) (*Change,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
a.thread.SetHeads([]string{ch.Id})
|
a.treeStorage.SetHeads([]string{ch.Id})
|
||||||
return ch, nil
|
return ch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ func (a *aclTree) AddChanges(changes ...*Change) (AddResult, error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
a.removeOrphans()
|
a.removeOrphans()
|
||||||
a.thread.SetHeads(a.fullTree.Heads())
|
a.treeStorage.SetHeads(a.fullTree.Heads())
|
||||||
a.Unlock()
|
a.Unlock()
|
||||||
switch mode {
|
switch mode {
|
||||||
case Append:
|
case Append:
|
||||||
@ -247,11 +247,11 @@ func (a *aclTree) AddChanges(changes ...*Change) (AddResult, error) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for _, ch := range changes {
|
for _, ch := range changes {
|
||||||
err = a.thread.AddChange(ch)
|
err = a.treeStorage.AddChange(ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AddResult{}, err
|
return AddResult{}, err
|
||||||
}
|
}
|
||||||
a.thread.AddOrphans(ch.Id)
|
a.treeStorage.AddOrphans(ch.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
prevHeads := a.fullTree.Heads()
|
prevHeads := a.fullTree.Heads()
|
||||||
@ -265,7 +265,7 @@ func (a *aclTree) AddChanges(changes ...*Change) (AddResult, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
case Rebuild:
|
case Rebuild:
|
||||||
err = a.rebuildFromThread(false)
|
err = a.rebuildFromStorage(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AddResult{}, err
|
return AddResult{}, err
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ func (a *aclTree) AddChanges(changes ...*Change) (AddResult, error) {
|
|||||||
Summary: AddResultSummaryRebuild,
|
Summary: AddResultSummaryRebuild,
|
||||||
}, nil
|
}, nil
|
||||||
default:
|
default:
|
||||||
// just rebuilding the state from start without reloading everything from thread
|
// just rebuilding the state from start without reloading everything from tree storage
|
||||||
// as an optimization we could've started from current heads, but I didn't implement that
|
// as an optimization we could've started from current heads, but I didn't implement that
|
||||||
a.aclState, err = a.aclStateBuilder.Build()
|
a.aclState, err = a.aclStateBuilder.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildThreadWithACL(t *testing.T) {
|
func Test_BuildTreeStorageWithACL(t *testing.T) {
|
||||||
keychain := treestoragebuilder.NewKeychain()
|
keychain := treestoragebuilder.NewKeychain()
|
||||||
keychain.AddSigningKey("A")
|
keychain.AddSigningKey("A")
|
||||||
keychain.AddEncryptionKey("A")
|
keychain.AddEncryptionKey("A")
|
||||||
@ -32,10 +32,10 @@ func TestBuildThreadWithACL(t *testing.T) {
|
|||||||
t.Fatalf("build should not return error")
|
t.Fatalf("build should not return error")
|
||||||
}
|
}
|
||||||
if len(thr.Heads()) == 0 {
|
if len(thr.Heads()) == 0 {
|
||||||
t.Fatalf("thread should have non-empty heads")
|
t.Fatalf("tree storage should have non-empty heads")
|
||||||
}
|
}
|
||||||
if thr.Header() == nil {
|
if thr.Header() == nil {
|
||||||
t.Fatalf("thread should have non-empty header")
|
t.Fatalf("tree storage should have non-empty header")
|
||||||
}
|
}
|
||||||
assert.Equal(t, thr.Heads()[0], thr.Header().FirstChangeId)
|
assert.Equal(t, thr.Heads()[0], thr.Header().FirstChangeId)
|
||||||
assert.NotEmpty(t, thr.TreeID())
|
assert.NotEmpty(t, thr.TreeID())
|
||||||
|
|||||||
@ -30,7 +30,7 @@ func NewInMemoryTreeStorage(firstChange *RawChange) (TreeStorage, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
threadId, err := cid.NewCIDFromBytes(marshalledHeader)
|
treeId, err := cid.NewCIDFromBytes(marshalledHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ func NewInMemoryTreeStorage(firstChange *RawChange) (TreeStorage, error) {
|
|||||||
changes[firstChange.Id] = firstChange
|
changes[firstChange.Id] = firstChange
|
||||||
|
|
||||||
return &inMemoryTreeStorage{
|
return &inMemoryTreeStorage{
|
||||||
id: threadId,
|
id: treeId,
|
||||||
header: header,
|
header: header,
|
||||||
heads: []string{firstChange.Id},
|
heads: []string{firstChange.Id},
|
||||||
orphans: nil,
|
orphans: nil,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user