diff --git a/core/indexer/indexer.go b/core/indexer/indexer.go index 740595a61..8245412a0 100644 --- a/core/indexer/indexer.go +++ b/core/indexer/indexer.go @@ -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 diff --git a/pkg/lib/localstore/objectstore/objects.go b/pkg/lib/localstore/objectstore/objects.go index ab507ec63..ac115eac4 100644 --- a/pkg/lib/localstore/objectstore/objects.go +++ b/pkg/lib/localstore/objectstore/objects.go @@ -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() {