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

Merge pull request #1459 from anyproto/go-3737-fix-type-reinstall

GO-3737 Fix type reinstall
This commit is contained in:
Kirill Stonozhenko 2024-08-08 13:21:55 +03:00 committed by GitHub
commit fa0deaf072
Signed by: github
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 66 deletions

View file

@ -72,29 +72,28 @@ func (p *Archive) Relations(_ *state.State) relationutils.Relations {
return nil
}
func (p *Archive) updateObjects(info smartblock.ApplyInfo) (err error) {
func (p *Archive) updateObjects(_ smartblock.ApplyInfo) (err error) {
archivedIds, err := p.GetIds()
if err != nil {
return
}
records, err := p.objectStore.Query(database.Query{
Filters: []*model.BlockContentDataviewFilter{
{
RelationKey: bundle.RelationKeyIsArchived.String(),
Condition: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.Bool(true),
},
{
RelationKey: bundle.RelationKeySpaceId.String(),
Condition: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.String(p.SpaceID()),
},
records, err := p.objectStore.QueryRaw(&database.Filters{FilterObj: database.FiltersAnd{
database.FilterEq{
Key: bundle.RelationKeyIsArchived.String(),
Cond: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.Bool(true),
},
})
database.FilterEq{
Key: bundle.RelationKeySpaceId.String(),
Cond: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.String(p.SpaceID()),
},
}}, 0, 0)
if err != nil {
return
}
var storeArchivedIds = make([]string, 0, len(records))
for _, rec := range records {
storeArchivedIds = append(storeArchivedIds, pbtypes.GetString(rec.Details, bundle.RelationKeyId.String()))

View file

@ -17,7 +17,7 @@ func NewArchiveTest(ctrl *gomock.Controller) (*Archive, error) {
sb := smarttest.New("root")
objectStore := testMock.NewMockObjectStore(ctrl)
objectStore.EXPECT().GetDetails(gomock.Any()).AnyTimes()
objectStore.EXPECT().Query(gomock.Any()).AnyTimes()
objectStore.EXPECT().QueryRaw(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
a := &Archive{
SmartBlock: sb,
Collection: collection.NewCollection(sb, objectStore),

View file

@ -8,7 +8,6 @@ import (
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
"github.com/gogo/protobuf/types"
"github.com/samber/lo"
"go.uber.org/zap"
"github.com/anyproto/anytype-heart/core/block/editor/objecttype"
@ -165,15 +164,6 @@ func (s *service) reinstallBundledObjects(ctx context.Context, sourceSpace clien
return nil, nil, fmt.Errorf("query deleted objects: %w", err)
}
archivedObjects, err := s.queryArchivedObjects(space, sourceObjectIDs)
if err != nil {
log.Errorf("query archived objects: %w", err)
}
deletedObjects = lo.UniqBy(append(deletedObjects, archivedObjects...), func(record database.Record) string {
return pbtypes.GetString(record.Details, bundle.RelationKeyId.String())
})
var (
ids []string
objects []*types.Struct
@ -279,48 +269,32 @@ func (s *service) prepareDetailsForInstallingObject(
return details, nil
}
func (s *service) queryDeletedObjects(space clientspace.Space, sourceObjectIDs []string) (deletedObjects []database.Record, err error) {
deletedObjects, err = s.objectStore.Query(database.Query{
Filters: []*model.BlockContentDataviewFilter{
{
RelationKey: bundle.RelationKeySourceObject.String(),
Condition: model.BlockContentDataviewFilter_In,
Value: pbtypes.StringList(sourceObjectIDs),
func (s *service) queryDeletedObjects(space clientspace.Space, sourceObjectIDs []string) ([]database.Record, error) {
sourceList, err := pbtypes.ValueListWrapper(pbtypes.StringList(sourceObjectIDs))
if err != nil {
return nil, err
}
return s.objectStore.QueryRaw(&database.Filters{FilterObj: database.FiltersAnd{
database.FilterIn{
Key: bundle.RelationKeySourceObject.String(),
Value: sourceList,
},
database.FilterEq{
Key: bundle.RelationKeySpaceId.String(),
Cond: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.String(space.Id()),
},
database.FiltersOr{
database.FilterEq{
Key: bundle.RelationKeyIsDeleted.String(),
Cond: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.Bool(true),
},
{
RelationKey: bundle.RelationKeySpaceId.String(),
Condition: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.String(space.Id()),
},
{
RelationKey: bundle.RelationKeyIsDeleted.String(),
Condition: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.Bool(true),
database.FilterEq{
Key: bundle.RelationKeyIsArchived.String(),
Cond: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.Bool(true),
},
},
})
return
}
func (s *service) queryArchivedObjects(space clientspace.Space, sourceObjectIDs []string) (archivedObjects []database.Record, err error) {
archivedObjects, err = s.objectStore.Query(database.Query{
Filters: []*model.BlockContentDataviewFilter{
{
RelationKey: bundle.RelationKeySourceObject.String(),
Condition: model.BlockContentDataviewFilter_In,
Value: pbtypes.StringList(sourceObjectIDs),
},
{
RelationKey: bundle.RelationKeySpaceId.String(),
Condition: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.String(space.Id()),
},
{
RelationKey: bundle.RelationKeyIsArchived.String(),
Condition: model.BlockContentDataviewFilter_Equal,
Value: pbtypes.Bool(true),
},
},
})
return
}}, 0, 0)
}

View file

@ -49,6 +49,7 @@ type ObjectStore interface {
SubscribeForAll(callback func(rec database.Record))
// Query adds implicit filters on isArchived, isDeleted and objectType relations! To avoid them use QueryRaw
Query(q database.Query) (records []database.Record, err error)
QueryRaw(f *database.Filters, limit int, offset int) (records []database.Record, err error)