From f1bec3f8b126727a4fb71bdd8e643b531e9df42d Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Tue, 7 Dec 2021 17:27:39 +0100 Subject: [PATCH] refactor storeFileKeys to include state.Doc as arg to be more clear --- core/block/editor/smartblock/smartblock.go | 16 +++++++++++----- util/builtinobjects/builtinobjects.go | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/block/editor/smartblock/smartblock.go b/core/block/editor/smartblock/smartblock.go index c94b1b64a..c4d1834dd 100644 --- a/core/block/editor/smartblock/smartblock.go +++ b/core/block/editor/smartblock/smartblock.go @@ -221,7 +221,10 @@ func (sb *smartBlock) Init(ctx *InitContext) (err error) { sb.objectStore = ctx.ObjectStore sb.lastDepDetails = map[string]*pb.EventObjectDetailsSet{} - sb.storeFileKeys() + if ctx.State != nil { + // need to store file keys in case we have some new files in the state + sb.storeFileKeys(ctx.State) + } sb.Doc.BlocksInit(sb.Doc.(simple.DetailsService)) if ctx.State == nil { @@ -1335,7 +1338,7 @@ func (sb *smartBlock) StateAppend(f func(d state.Doc) (s *state.State, err error ContextId: sb.Id(), }) } - sb.storeFileKeys() + sb.storeFileKeys(s) if hasDepIds(&act) { sb.CheckSubscriptions() } @@ -1364,7 +1367,7 @@ func (sb *smartBlock) StateRebuild(d state.Doc) (err error) { }) } } - sb.storeFileKeys() + sb.storeFileKeys(d) sb.CheckSubscriptions() sb.reportChange(sb.Doc.(*state.State)) sb.execHooks(HookAfterApply) @@ -1450,8 +1453,11 @@ func getChangedFileHashes(s *state.State, fileDetailKeys []string, act undo.Acti return } -func (sb *smartBlock) storeFileKeys() { - keys := sb.Doc.GetFileKeys() +func (sb *smartBlock) storeFileKeys(doc state.Doc) { + if doc == nil { + return + } + keys := doc.GetFileKeys() if len(keys) == 0 { return } diff --git a/util/builtinobjects/builtinobjects.go b/util/builtinobjects/builtinobjects.go index 9fecddc1b..1870fb362 100644 --- a/util/builtinobjects/builtinobjects.go +++ b/util/builtinobjects/builtinobjects.go @@ -128,12 +128,11 @@ func (b *builtinObjects) createObject(ctx context.Context, rd io.ReadCloser) (er } st.SetRootId(newId) - st = st.Copy() st.RemoveDetail(bundle.RelationKeyCreator.String(), bundle.RelationKeyLastModifiedBy.String()) st.SetLocalDetail(bundle.RelationKeyCreator.String(), pbtypes.String(addr.AnytypeProfileId)) st.SetLocalDetail(bundle.RelationKeyLastModifiedBy.String(), pbtypes.String(addr.AnytypeProfileId)) st.InjectDerivedDetails() - if err = b.validate(st.Copy()); err != nil { + if err = b.validate(st); err != nil { return }