mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Use string hash
This commit is contained in:
parent
eaa9af16dd
commit
253968a8d8
5 changed files with 25 additions and 29 deletions
|
@ -2,6 +2,7 @@ package ldiff
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/zeebo/blake3"
|
||||
)
|
||||
|
@ -37,9 +38,10 @@ func (d *diffContainer) Set(elements ...Element) {
|
|||
for _, el := range elements {
|
||||
hasher.Reset()
|
||||
hasher.WriteString(el.Head)
|
||||
stringHash := hex.EncodeToString(hasher.Sum(nil))
|
||||
d.newDiff.Set(Element{
|
||||
Id: el.Id,
|
||||
Head: string(hasher.Sum(nil)),
|
||||
Head: stringHash,
|
||||
})
|
||||
}
|
||||
d.oldDiff.Set(elements...)
|
||||
|
|
|
@ -38,7 +38,6 @@ type TreeHeads struct {
|
|||
type HeadSync interface {
|
||||
app.ComponentRunnable
|
||||
ExternalIds() []string
|
||||
DebugAllHeads() (res []TreeHeads)
|
||||
AllIds() []string
|
||||
HandleRangeRequest(ctx context.Context, req *spacesyncproto.HeadSyncRequest) (resp *spacesyncproto.HeadSyncResponse, err error)
|
||||
}
|
||||
|
@ -123,18 +122,6 @@ func (h *headSync) ExternalIds() []string {
|
|||
})
|
||||
}
|
||||
|
||||
func (h *headSync) DebugAllHeads() (res []TreeHeads) {
|
||||
els := h.diffContainer.NewDiff().Elements()
|
||||
for _, el := range els {
|
||||
idHead := TreeHeads{
|
||||
Id: el.Id,
|
||||
Heads: splitString(el.Head),
|
||||
}
|
||||
res = append(res, idHead)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (h *headSync) Close(ctx context.Context) (err error) {
|
||||
h.syncer.Close()
|
||||
h.periodicSync.Close()
|
||||
|
|
|
@ -55,17 +55,17 @@ func (mr *MockStateStorageMockRecorder) GetState(arg0 any) *gomock.Call {
|
|||
}
|
||||
|
||||
// SetHash mocks base method.
|
||||
func (m *MockStateStorage) SetHash(arg0 context.Context, arg1 string) error {
|
||||
func (m *MockStateStorage) SetHash(arg0 context.Context, arg1, arg2 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetHash", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "SetHash", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetHash indicates an expected call of SetHash.
|
||||
func (mr *MockStateStorageMockRecorder) SetHash(arg0, arg1 any) *gomock.Call {
|
||||
func (mr *MockStateStorageMockRecorder) SetHash(arg0, arg1, arg2 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHash", reflect.TypeOf((*MockStateStorage)(nil).SetHash), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHash", reflect.TypeOf((*MockStateStorage)(nil).SetHash), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// SetObserver mocks base method.
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package headsync
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func concatStrings(strs []string) string {
|
||||
if len(strs) == 1 {
|
||||
return strs[0]
|
||||
}
|
||||
var (
|
||||
b strings.Builder
|
||||
totalLen int
|
||||
|
@ -17,11 +22,3 @@ func concatStrings(strs []string) string {
|
|||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func splitString(str string) (res []string) {
|
||||
const cidLen = 59
|
||||
for i := 0; i < len(str); i += cidLen {
|
||||
res = append(res, str[i:i+cidLen])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/anyproto/any-sync/app"
|
||||
"github.com/anyproto/any-sync/commonspace/acl/aclclient"
|
||||
"github.com/anyproto/any-sync/commonspace/headsync"
|
||||
"github.com/anyproto/any-sync/commonspace/headsync/headstorage"
|
||||
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||
"github.com/anyproto/any-sync/commonspace/object/acl/syncacl"
|
||||
"github.com/anyproto/any-sync/commonspace/object/treesyncer"
|
||||
|
@ -145,8 +146,17 @@ func (s *space) StoredIds() []string {
|
|||
return s.headSync.ExternalIds()
|
||||
}
|
||||
|
||||
func (s *space) DebugAllHeads() []headsync.TreeHeads {
|
||||
return s.headSync.DebugAllHeads()
|
||||
func (s *space) DebugAllHeads() (heads []headsync.TreeHeads) {
|
||||
s.storage.HeadStorage().IterateEntries(context.Background(), headstorage.IterOpts{}, func(entry headstorage.HeadsEntry) (bool, error) {
|
||||
if entry.CommonSnapshot != "" {
|
||||
heads = append(heads, headsync.TreeHeads{
|
||||
Id: entry.Id,
|
||||
Heads: entry.Heads,
|
||||
})
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
return heads
|
||||
}
|
||||
|
||||
func (s *space) DeleteTree(ctx context.Context, id string) (err error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue