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:
parent
c38a48e290
commit
cbf023ba1d
1 changed files with 24 additions and 20 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue