1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-11 02:13:41 +09:00

GO-3626: Notifications: check that object is already derived

This commit is contained in:
Sergey 2024-06-18 12:25:11 +02:00
parent c38a48e290
commit cbf023ba1d
No known key found for this signature in database
GPG key ID: 3B6BEF79160221C6

View file

@ -9,6 +9,7 @@ import (
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
"github.com/anyproto/any-sync/net/peer"
"github.com/anyproto/anytype-heart/core/block/cache"
"github.com/anyproto/anytype-heart/core/block/editor/smartblock"
@ -22,6 +23,7 @@ import (
"github.com/anyproto/anytype-heart/pkg/lib/logging"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/space"
"github.com/anyproto/anytype-heart/space/spacecore/peermanager"
"github.com/anyproto/anytype-heart/util/badgerhelper"
)
@ -279,30 +281,32 @@ func (n *notificationService) loadNotificationObject(ctx context.Context) {
if err != nil {
return
}
notificationObject, err := techSpace.DeriveTreeObject(ctx, objectcache.TreeDerivationParams{
Key: uk,
InitFunc: func(id string) *smartblock.InitContext {
return &smartblock.InitContext{
Ctx: ctx,
SpaceID: techSpace.Id(),
State: state.NewDoc(id, nil).(*state.State),
}
},
})
if err != nil && !errors.Is(err, treestorage.ErrTreeExists) {
log.Errorf("failed to derive notification object: %v", err)
objectId, err := techSpace.DeriveObjectID(ctx, uk)
if err != nil {
log.Errorf("failed to derive notification object id: %v", err)
return
}
if err == nil {
n.notificationId = notificationObject.Id()
}
if errors.Is(err, treestorage.ErrTreeExists) {
notificationID, err := techSpace.DeriveObjectID(ctx, uk)
if err != nil {
log.Errorf("failed to derive notification object id: %v", err)
n.notificationId = objectId
ctx = context.WithValue(ctx, peermanager.ContextPeerFindDeadlineKey, time.Now().Add(30*time.Second))
ctx = peer.CtxWithPeerId(ctx, peer.CtxResponsiblePeers)
_, err = techSpace.GetObject(ctx, objectId)
if err != nil {
_, err := techSpace.DeriveTreeObject(ctx, objectcache.TreeDerivationParams{
Key: uk,
InitFunc: func(id string) *smartblock.InitContext {
return &smartblock.InitContext{
Ctx: ctx,
SpaceID: techSpace.Id(),
State: state.NewDoc(id, nil).(*state.State),
}
},
})
if err != nil && !errors.Is(err, treestorage.ErrTreeExists) {
log.Errorf("failed to derive notification object: %v", err)
return
}
n.notificationId = notificationID
}
n.indexNotifications(ctx)
}