1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-10 18:10:49 +09:00

Merge pull request #1300 from anytypeio/fix-objectstore-crash

fix getObjectDetails crash
This commit is contained in:
Roman Khafizianov 2021-11-18 18:55:49 +04:00 committed by GitHub
commit bcba5bfdd0
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -580,7 +580,7 @@ func (i *indexer) reindexDoc(ctx context.Context, id string, indexesWereRemoved
var curDetails *types.Struct
curDetailsO, _ := i.store.GetDetails(id)
if curDetailsO != nil {
if curDetailsO.GetDetails().GetFields() != nil {
curDetails = curDetailsO.Details
}
// compare only real object scoped details

View file

@ -3,6 +3,7 @@ package objectstore
import (
"encoding/binary"
"fmt"
"runtime/debug"
"strings"
"sync"
"time"
@ -2027,6 +2028,15 @@ func (m *dsObjectStore) updateSnippet(txn ds.Txn, id string, snippet string) err
}
func (m *dsObjectStore) updateDetails(txn ds.Txn, id string, oldDetails *model.ObjectDetails, newDetails *model.ObjectDetails) error {
t, err := smartblock.SmartBlockTypeFromID(id)
if err != nil {
log.Errorf("updateDetails: failed to detect smartblock type for %s: %s", id, err.Error())
return fmt.Errorf("updateDetails: failed to detect smartblock type for %s: %s", id, err.Error())
} else if indexdetails, _ := t.Indexable(); !indexdetails {
log.Errorf("updateDetails: trying to index non-indexable sb %s(%d): %s", id, t, string(debug.Stack()))
return fmt.Errorf("updateDetails: trying to index non-indexable sb %s(%d)", id, t)
}
metrics.ObjectDetailsUpdatedCounter.Inc()
detailsKey := pagesDetailsBase.ChildString(id)
@ -2205,6 +2215,11 @@ func getObjectDetails(txn ds.Txn, id string) (*model.ObjectDetails, error) {
} else if err := proto.Unmarshal(val, &details); err != nil {
return nil, fmt.Errorf("failed to unmarshal details: %w", err)
}
if details.GetDetails().GetFields() == nil {
log.Errorf("getObjectDetails got nil record for %s", id)
details.Details = &types.Struct{Fields: map[string]*types.Value{}}
}
details.Details.Fields[bundle.RelationKeyId.String()] = pbtypes.String(id)
for k, v := range details.GetDetails().GetFields() {