1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 17:44:59 +09:00

GO-1084: Clarify code

This commit is contained in:
Sergey 2023-04-25 18:17:59 +02:00 committed by Mikhail Iudin
parent 4b3618b416
commit 3d0c91a895
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
4 changed files with 7 additions and 10 deletions

View file

@ -36,7 +36,7 @@ type Service interface {
RemoveStaticSource(id string)
GetDetailsFromIdBasedSource(id string) (*types.Struct, error)
SourceTypeBySbType(blockType smartblock.SmartBlockType) (SourceType, error)
IDsListerBySmartblockType(blockType smartblock.SmartBlockType) (IDsLister, error)
app.Component
}
@ -124,7 +124,7 @@ func (s *service) NewSource(id string, spaceID string, buildOptions commonspace.
return newTreeSource(id, deps)
}
func (s *service) SourceTypeBySbType(blockType smartblock.SmartBlockType) (SourceType, error) {
func (s *service) IDsListerBySmartblockType(blockType smartblock.SmartBlockType) (IDsLister, error) {
switch blockType {
case smartblock.SmartBlockTypeAnytypeProfile:
return &anytypeProfile{}, nil
@ -143,11 +143,10 @@ func (s *service) SourceTypeBySbType(blockType smartblock.SmartBlockType) (Sourc
return nil, err
} else {
return &source{
smartblockType: blockType,
coreService: s.coreService,
spaceService: s.spaceService,
smartblockType: blockType,
sbtProvider: s.sbtProvider,
fileService: s.fileService,
}, nil
}
}

View file

@ -61,14 +61,13 @@ type SourceIdEndodedDetails interface {
DetailsFromId() (*types.Struct, error)
}
// TODO Extract implementation from sources impl
type SourceType interface {
type IDsLister interface {
ListIds() ([]string, error)
}
type SourceWithType interface {
Source
SourceType
IDsLister
}
var ErrUnknownDataFormat = fmt.Errorf("unknown data format: you may need to upgrade anytype in order to open this page")

View file

@ -54,7 +54,6 @@ func (s *static) PushChange(params PushChangeParams) (id string, err error) {
}
func (s *static) ListIds() (result []string, err error) {
// TODO move this code to service.ListStaticIDs
s.s.mu.Lock()
defer s.s.mu.Unlock()
for id, src := range s.s.staticIds {

View file

@ -682,11 +682,11 @@ func (i *indexer) getObjectInfo(ctx context.Context, id string) (info smartblock
func (i *indexer) getIdsForTypes(sbt ...smartblock.SmartBlockType) ([]string, error) {
var ids []string
for _, t := range sbt {
st, err := i.source.SourceTypeBySbType(t)
lister, err := i.source.IDsListerBySmartblockType(t)
if err != nil {
return nil, err
}
idsT, err := st.ListIds()
idsT, err := lister.ListIds()
if err != nil {
return nil, err
}