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

Integrate: fix setter

This commit is contained in:
Sergey 2024-08-01 17:44:51 +02:00
parent 1fb76761f6
commit c36b61f39f
No known key found for this signature in database
GPG key ID: 3B6BEF79160221C6
29 changed files with 172 additions and 119 deletions

View file

@ -200,7 +200,7 @@ func (uw *UpdateWatcher) updateBackLinksInObject(id string, backlinksUpdate *bac
}
}
current.Set(bundle.RelationKeyBacklinks, backlinks)
current.SetStringList(bundle.RelationKeyBacklinks, backlinks)
return current, true, nil
}

View file

@ -94,7 +94,7 @@ func applyDetailUpdates(oldDetails *domain.Details, updates []*detailUpdate) *do
if update.value == nil {
newDetails.Delete(update.key)
} else {
newDetails.Set(update.key, update.value)
newDetails.SetUnsafe(update.key, update.value)
}
}
return newDetails

View file

@ -165,7 +165,7 @@ func createTargetObjectDetails(nameText string, layout model.ObjectTypeLayout) *
details := domain.NewDetails()
// Without this check title will be duplicated in template.WithNameToFirstBlock
if layout != model.ObjectType_note {
details.Set(bundle.RelationKeyName, nameText)
details.SetString(bundle.RelationKeyName, nameText)
}
return details
}

View file

@ -65,5 +65,5 @@ func SetLastUsedDateForInitialObjectType(id string, details *domain.Details) {
// we do this trick to order crucial Anytype object types by last date
lastUsed := time.Now().Add(time.Duration(-1 * priority * int64(maxInstallationTime))).Unix()
details.Set(bundle.RelationKeyLastUsedDate, lastUsed)
details.SetInt64(bundle.RelationKeyLastUsedDate, lastUsed)
}

View file

@ -58,8 +58,8 @@ func ExtractCustomState(st *state.State) (userState *state.State, err error) {
newState.AddRelationLinks(st.GetRelationLinks()...)
newStateDetails := st.Details().ShallowCopy()
newName := newStateDetails.GetString(bundle.RelationKeyName) + " [migrated]"
newStateDetails.Set(bundle.RelationKeyName, newName)
newStateDetails.Set(bundle.RelationKeyIsHidden, false)
newStateDetails.SetString(bundle.RelationKeyName, newName)
newStateDetails.SetBool(bundle.RelationKeyIsHidden, false)
newState.SetDetails(newStateDetails)
// remove the identity block
newState.Unlink(identityBlockId)

View file

@ -271,7 +271,7 @@ func (s *State) changeBlockDetailsSet(set *pb.ChangeDetailsSet) error {
s.details = det.ShallowCopy()
}
if set.Value != nil {
s.details.Set(domain.RelationKey(set.Key), pbtypes.ProtoToAny(set.Value))
s.details.SetProtoValue(domain.RelationKey(set.Key), set.Value)
} else {
s.details.Delete(domain.RelationKey(set.Key))
}

View file

@ -940,7 +940,7 @@ func (s *State) SetLocalDetail(key domain.RelationKey, value any) {
log.Errorf("invalid value for pb %s: %v", key, err)
}
s.localDetails.Set(key, value)
s.localDetails.SetUnsafe(key, value)
return
}
@ -994,7 +994,7 @@ func (s *State) SetDetail(key domain.RelationKey, value any) {
log.Errorf("invalid value for pb %s: %v", key, err)
}
s.details.Set(key, value)
s.details.SetUnsafe(key, value)
return
}

View file

@ -286,7 +286,7 @@ type Icon struct {
func SetIcon(details *domain.Details, icon *Icon) *model.RelationLink {
if icon.Emoji != nil {
details.Set(bundle.RelationKeyIconEmoji, *icon.Emoji)
details.SetString(bundle.RelationKeyIconEmoji, *icon.Emoji)
}
var linkToIconImage string
if icon.Type == External && icon.External != nil {
@ -296,7 +296,7 @@ func SetIcon(details *domain.Details, icon *Icon) *model.RelationLink {
linkToIconImage = icon.File.URL
}
if linkToIconImage != "" {
details.Set(bundle.RelationKeyIconImage, linkToIconImage)
details.SetString(bundle.RelationKeyIconImage, linkToIconImage)
return &model.RelationLink{
Key: bundle.RelationKeyIconImage.String(),
Format: model.RelationFormat_file,

View file

@ -126,7 +126,7 @@ func (s *service) createObjectInSpace(
Details: details.ToProto(),
})
case bundle.TypeKeySet:
details.Set(bundle.RelationKeyLayout, model.ObjectType_set)
details.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_set))
return s.createSet(ctx, space, createSetRequest{
Details: details,
InternalFlags: req.InternalFlags,
@ -134,7 +134,7 @@ func (s *service) createObjectInSpace(
})
case bundle.TypeKeyCollection:
var st *state.State
details.Set(bundle.RelationKeyLayout, model.ObjectType_collection)
details.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_collection))
_, details, st, err = s.collectionService.CreateCollection(details, req.InternalFlags)
if err != nil {
return "", nil, err

View file

@ -230,9 +230,9 @@ func (s *service) prepareDetailsForInstallingObject(
spaceID := spc.Id()
sourceId := details.GetString(bundle.RelationKeyId)
details.Set(bundle.RelationKeySpaceId, spaceID)
details.Set(bundle.RelationKeySourceObject, sourceId)
details.Set(bundle.RelationKeyIsReadonly, false)
details.SetString(bundle.RelationKeySpaceId, spaceID)
details.SetString(bundle.RelationKeySourceObject, sourceId)
details.SetBool(bundle.RelationKeyIsReadonly, false)
if isNewSpace {
objecttype.SetLastUsedDateForInitialObjectType(sourceId, details)
@ -252,7 +252,7 @@ func (s *service) prepareDetailsForInstallingObject(
if err != nil {
return nil, fmt.Errorf("prepare recommended relation ids: %w", err)
}
details.Set(bundle.RelationKeyRecommendedRelations, recommendedRelationIds)
details.SetStringList(bundle.RelationKeyRecommendedRelations, recommendedRelationIds)
}
objectTypes := details.GetStringList(bundle.RelationKeyRelationFormatObjectTypes)
@ -272,7 +272,7 @@ func (s *service) prepareDetailsForInstallingObject(
}
objectTypes[i] = id
}
details.Set(bundle.RelationKeyRelationFormatObjectTypes, objectTypes)
details.SetStringList(bundle.RelationKeyRelationFormatObjectTypes, objectTypes)
}
return details, nil

View file

@ -28,7 +28,7 @@ func (s *service) createObjectType(ctx context.Context, space clientspace.Space,
object := details.ShallowCopy()
if !object.Has(bundle.RelationKeyRecommendedLayout) {
object.Set(bundle.RelationKeyRecommendedLayout, model.ObjectType_basic)
object.SetInt64(bundle.RelationKeyRecommendedLayout, int64(model.ObjectType_basic))
}
if len(object.GetStringList(bundle.RelationKeyRecommendedRelations)) == 0 {
err = s.fillRecommendedRelationsFromLayout(ctx, space, object)
@ -37,8 +37,8 @@ func (s *service) createObjectType(ctx context.Context, space clientspace.Space,
}
}
object.Set(bundle.RelationKeyId, id)
object.Set(bundle.RelationKeyLayout, model.ObjectType_objectType)
object.SetString(bundle.RelationKeyId, id)
object.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_objectType))
createState := state.NewDocWithUniqueKey("", nil, uniqueKey).(*state.State)
createState.SetDetails(object)
@ -69,7 +69,7 @@ func (s *service) fillRecommendedRelationsFromLayout(ctx context.Context, space
if err != nil {
return fmt.Errorf("prepare recommended relation ids: %w", err)
}
details.Set(bundle.RelationKeyRecommendedRelations, recommendedRelationIds)
details.SetStringList(bundle.RelationKeyRecommendedRelations, recommendedRelationIds)
return nil
}

View file

@ -37,21 +37,21 @@ func (s *service) createRelation(ctx context.Context, space clientspace.Space, d
if key == "" {
key = domain.RelationKey(bson.NewObjectId().Hex())
} else if bundle.HasRelation(key) {
object.Set(bundle.RelationKeySourceObject, addr.BundledRelationURLPrefix+key)
object.SetString(bundle.RelationKeySourceObject, string(addr.BundledRelationURLPrefix+key))
}
uniqueKey, err := domain.NewUniqueKey(coresb.SmartBlockTypeRelation, string(key))
if err != nil {
return "", nil, err
}
object.Set(bundle.RelationKeyUniqueKey, uniqueKey.Marshal())
object.Set(bundle.RelationKeyId, id)
object.Set(bundle.RelationKeyRelationKey, key)
object.SetString(bundle.RelationKeyUniqueKey, uniqueKey.Marshal())
object.SetString(bundle.RelationKeyId, id)
object.SetString(bundle.RelationKeyRelationKey, string(key))
if details.GetInt64(bundle.RelationKeyRelationFormat) == int64(model.RelationFormat_status) {
object.Set(bundle.RelationKeyRelationMaxCount, 1)
object.SetInt64(bundle.RelationKeyRelationMaxCount, 1)
}
// objectTypes := object.GetStringListOrDefault(bundle.RelationKeyRelationFormatObjectTypes, nil)
// todo: check the objectTypes
object.Set(bundle.RelationKeyLayout, model.ObjectType_relation)
object.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_relation))
createState := state.NewDocWithUniqueKey("", nil, uniqueKey).(*state.State)
createState.SetDetails(object)

View file

@ -32,8 +32,8 @@ func (s *service) createRelationOption(ctx context.Context, space clientspace.Sp
}
object = details.ShallowCopy()
object.Set(bundle.RelationKeyUniqueKey, uniqueKey.Marshal())
object.Set(bundle.RelationKeyLayout, model.ObjectType_relationOption)
object.SetString(bundle.RelationKeyUniqueKey, uniqueKey.Marshal())
object.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_relationOption))
createState := state.NewDocWithUniqueKey("", nil, uniqueKey).(*state.State)
createState.SetDetails(object)

View file

@ -53,7 +53,7 @@ func (b *Bookmark) GetContent() *model.BlockContentBookmark {
func (b *Bookmark) ToDetails(origin objectorigin.ObjectOrigin) *domain.Details {
details := domain.NewDetails()
details.Set(bundle.RelationKeySource, pbtypes.String(b.content.Url))
details.SetString(bundle.RelationKeySource, b.content.Url)
origin.AddToDetails(details)
return details
}

View file

@ -13,7 +13,6 @@ import (
"github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/addr"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/util/pbtypes"
)
func NewBundledRelation(id string) (s Source) {
@ -56,11 +55,11 @@ func (v *bundledRelation) getDetails(id string) (p *domain.Details, err error) {
rel.Creator = addr.AnytypeProfileId
wrapperRelation := relationutils.Relation{Relation: rel}
details := wrapperRelation.ToDetails() // bundle.GetDetailsForBundledRelation(rel)
details.Set(bundle.RelationKeySpaceId, pbtypes.String(addr.AnytypeMarketplaceWorkspace))
details.Set(bundle.RelationKeyIsReadonly, pbtypes.Bool(true))
details.Set(bundle.RelationKeyType, pbtypes.String(bundle.TypeKeyRelation.BundledURL()))
details.Set(bundle.RelationKeyId, pbtypes.String(id))
details.Set(bundle.RelationKeyOrigin, pbtypes.Int64(int64(model.ObjectOrigin_builtin)))
details.SetString(bundle.RelationKeySpaceId, addr.AnytypeMarketplaceWorkspace)
details.SetBool(bundle.RelationKeyIsReadonly, true)
details.SetString(bundle.RelationKeyType, bundle.TypeKeyRelation.BundledURL())
details.SetString(bundle.RelationKeyId, id)
details.SetInt64(bundle.RelationKeyOrigin, int64(model.ObjectOrigin_builtin))
return details, nil
}

View file

@ -64,37 +64,46 @@ func JsonToProto(v *fastjson.Value) (*Details, error) {
return
}
// key is copied
val, err := JsonValueToProto(v)
err := jsonValueToAny(res, RelationKey(k), v)
if err != nil {
visitErr = err
}
res.Set(RelationKey(k), val)
})
return res, visitErr
}
func JsonValueToProto(val *fastjson.Value) (any, error) {
func jsonValueToAny(d *Details, key RelationKey, val *fastjson.Value) error {
switch val.Type() {
case fastjson.TypeNumber:
return val.Float64()
v, err := val.Float64()
if err != nil {
return fmt.Errorf("number: %w", err)
}
d.SetFloat(key, v)
return nil
case fastjson.TypeString:
v, err := val.StringBytes()
if err != nil {
return nil, fmt.Errorf("string: %w", err)
return fmt.Errorf("string: %w", err)
}
return string(v), nil
d.SetString(key, string(v))
return nil
case fastjson.TypeTrue:
return true, nil
d.SetBool(key, true)
return nil
case fastjson.TypeFalse:
return false, nil
d.SetBool(key, false)
return nil
case fastjson.TypeArray:
arrVals, err := val.Array()
if err != nil {
return nil, fmt.Errorf("array: %w", err)
return fmt.Errorf("array: %w", err)
}
// Assume string as default type
if len(arrVals) == 0 {
return []string{}, nil
d.SetStringList(key, nil)
return nil
}
firstVal := arrVals[0]
@ -103,27 +112,29 @@ func JsonValueToProto(val *fastjson.Value) (any, error) {
for _, arrVal := range arrVals {
v, err := arrVal.StringBytes()
if err != nil {
return nil, fmt.Errorf("array item: string: %w", err)
return fmt.Errorf("array item: string: %w", err)
}
res = append(res, string(v))
}
return res, nil
d.SetStringList(key, res)
return nil
} else if firstVal.Type() == fastjson.TypeNumber {
res := make([]float64, 0, len(arrVals))
for _, arrVal := range arrVals {
v, err := arrVal.Float64()
if err != nil {
return nil, fmt.Errorf("array item: number: %w", err)
return fmt.Errorf("array item: number: %w", err)
}
res = append(res, v)
}
return res, nil
d.SetFloatList(key, res)
return nil
} else {
return nil, fmt.Errorf("unsupported array type %s", firstVal.Type())
return fmt.Errorf("unsupported array type %s", firstVal.Type())
}
}
// TODO What is the matter with nil value?
return nil, nil
return fmt.Errorf("unsupported type %s", val.Type())
}
func ProtoToJson(arena *fastjson.Arena, details *Details) *fastjson.Value {
@ -180,7 +191,7 @@ func StructDiff(st1, st2 *Details) *Details {
if st2 == nil {
diff = NewDetails()
st1.Iterate(func(k RelationKey, v any) bool {
diff.Set(k, Tombstone{})
diff.SetUnsafe(k, Tombstone{})
return true
})
return diff
@ -192,7 +203,7 @@ func StructDiff(st1, st2 *Details) *Details {
if diff == nil {
diff = NewDetails()
}
diff.Set(k2, v2)
diff.SetUnsafe(k2, v2)
}
return true
})
@ -202,7 +213,7 @@ func StructDiff(st1, st2 *Details) *Details {
if diff == nil {
diff = NewDetails()
}
diff.Set(k, Tombstone{})
diff.SetUnsafe(k, Tombstone{})
}
return true
})

View file

@ -5,14 +5,17 @@ import (
"fmt"
"strings"
"github.com/gogo/protobuf/types"
"golang.org/x/exp/slices"
"github.com/anyproto/anytype-heart/util/pbtypes"
)
func (d *GenericMap[K]) Len() int {
return len(d.data)
}
func (d *GenericMap[K]) Set(key K, value any) {
func (d *GenericMap[K]) SetUnsafe(key K, value any) {
// TODO Convert number value to float, convert number list value to floats
// TODO TEMP panic
@ -23,6 +26,49 @@ func (d *GenericMap[K]) Set(key K, value any) {
d.data[key] = value
}
func (d *GenericMap[K]) SetBool(key K, value bool) {
d.data[key] = value
}
func (d *GenericMap[K]) SetString(key K, value string) {
d.data[key] = value
}
func (d *GenericMap[K]) SetInt64(key K, value int64) {
d.data[key] = float64(value)
}
func (d *GenericMap[K]) SetFloat(key K, value float64) {
d.data[key] = value
}
func (d *GenericMap[K]) SetStringList(key K, value []string) {
d.data[key] = value
}
func (d *GenericMap[K]) SetFloatList(key K, value []float64) {
d.data[key] = value
}
func (d *GenericMap[K]) SetProtoValue(key K, value *types.Value) {
switch value.Kind.(type) {
case *types.Value_BoolValue:
d.SetBool(key, value.GetBoolValue())
case *types.Value_StringValue:
d.SetString(key, value.GetStringValue())
case *types.Value_NumberValue:
d.SetFloat(key, value.GetNumberValue())
case *types.Value_StructValue:
// TODO Not implemented
case *types.Value_ListValue:
if list := pbtypes.ListValueToFloats(value.GetListValue()); len(list) > 0 {
d.SetFloatList(key, list)
} else {
d.SetStringList(key, pbtypes.ListValueToStrings(value.GetListValue()))
}
}
}
func (d *GenericMap[K]) Delete(key K) {
delete(d.data, key)
}
@ -154,7 +200,7 @@ func (d *GenericMap[K]) Equal(other *GenericMap[K]) bool {
func (d *GenericMap[K]) Merge(other *GenericMap[K]) *GenericMap[K] {
res := d.ShallowCopy()
other.Iterate(func(k K, v any) bool {
res.Set(k, v)
res.SetUnsafe(k, v)
return true
})
return res

View file

@ -4,7 +4,6 @@ import (
"github.com/anyproto/anytype-heart/core/domain"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/util/pbtypes"
)
type ObjectOrigin struct {
@ -28,9 +27,9 @@ func (o ObjectOrigin) IsImported() bool {
func (o ObjectOrigin) AddToDetails(details *domain.Details) {
if o.Origin != model.ObjectOrigin_none {
details.Set(bundle.RelationKeyOrigin, pbtypes.Int64(int64(o.Origin)))
details.SetInt64(bundle.RelationKeyOrigin, int64(o.Origin))
if o.Origin == model.ObjectOrigin_import || o.Origin == model.ObjectOrigin_usecase {
details.Set(bundle.RelationKeyImportType, pbtypes.Int64(int64(o.ImportType)))
details.SetInt64(bundle.RelationKeyImportType, int64(o.ImportType))
}
}
}

View file

@ -54,24 +54,24 @@ func (f *file) audioDetails(ctx context.Context) (*domain.Details, error) {
d := domain.NewDetails()
if t.Album() != "" {
d.Set(bundle.RelationKeyAudioAlbum, t.Album())
d.SetString(bundle.RelationKeyAudioAlbum, t.Album())
}
if t.Artist() != "" {
d.Set(bundle.RelationKeyAudioArtist, t.Artist())
d.SetString(bundle.RelationKeyAudioArtist, t.Artist())
}
if t.Genre() != "" {
d.Set(bundle.RelationKeyAudioGenre, t.Genre())
d.SetString(bundle.RelationKeyAudioGenre, t.Genre())
}
if t.Lyrics() != "" {
d.Set(bundle.RelationKeyAudioLyrics, t.Lyrics())
d.SetString(bundle.RelationKeyAudioLyrics, t.Lyrics())
}
if n, _ := t.Track(); n != 0 {
d.Set(bundle.RelationKeyAudioAlbumTrackNumber, int64(n))
d.SetInt64(bundle.RelationKeyAudioAlbumTrackNumber, int64(n))
}
if t.Year() != 0 {
d.Set(bundle.RelationKeyReleasedYear, int64(t.Year()))
d.SetInt64(bundle.RelationKeyReleasedYear, int64(t.Year()))
}
d.Set(bundle.RelationKeyLayout, float64(model.ObjectType_audio))
d.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_audio))
return d, nil
}
@ -81,19 +81,19 @@ func (f *file) Details(ctx context.Context) (*domain.Details, domain.TypeKey, er
typeKey := bundle.TypeKeyFile
details := calculateCommonDetails(f.fileId, model.ObjectType_file, f.info.LastModifiedDate)
details.Set(bundle.RelationKeyFileMimeType, meta.Media)
details.Set(bundle.RelationKeyName, strings.TrimSuffix(meta.Name, filepath.Ext(meta.Name)))
details.Set(bundle.RelationKeyFileExt, strings.TrimPrefix(filepath.Ext(meta.Name), "."))
details.Set(bundle.RelationKeySizeInBytes, float64(meta.Size))
details.Set(bundle.RelationKeyAddedDate, float64(meta.Added.Unix()))
details.SetString(bundle.RelationKeyFileMimeType, meta.Media)
details.SetString(bundle.RelationKeyName, strings.TrimSuffix(meta.Name, filepath.Ext(meta.Name)))
details.SetString(bundle.RelationKeyFileExt, strings.TrimPrefix(filepath.Ext(meta.Name), "."))
details.SetFloat(bundle.RelationKeySizeInBytes, float64(meta.Size))
details.SetFloat(bundle.RelationKeyAddedDate, float64(meta.Added.Unix()))
if meta.Media == "application/pdf" {
typeKey = bundle.TypeKeyFile
details.Set(bundle.RelationKeyLayout, model.ObjectType_pdf)
details.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_pdf))
}
if strings.HasPrefix(meta.Media, "video") {
typeKey = bundle.TypeKeyVideo
details.Set(bundle.RelationKeyLayout, model.ObjectType_video)
details.SetInt64(bundle.RelationKeyLayout, int64(model.ObjectType_video))
}
if strings.HasPrefix(meta.Media, "audio") {

View file

@ -258,7 +258,7 @@ func (ind *indexer) buildDetails(ctx context.Context, id domain.FullFileId) (det
typeKey = bundle.TypeKeyImage
}
details.Set(bundle.RelationKeyFileIndexingStatus, int64(model.FileIndexingStatus_Indexed))
details.SetInt64(bundle.RelationKeyFileIndexingStatus, int64(model.FileIndexingStatus_Indexed))
return details, typeKey, nil
}

View file

@ -186,23 +186,23 @@ func (i *image) Details(ctx context.Context) (*domain.Details, error) {
}
if v := pbtypes.Get(largest.GetMeta(), "width"); v != nil {
details.Set(bundle.RelationKeyWidthInPixels, v.GetNumberValue())
details.SetFloat(bundle.RelationKeyWidthInPixels, v.GetNumberValue())
}
if v := pbtypes.Get(largest.GetMeta(), "height"); v != nil {
details.Set(bundle.RelationKeyHeightInPixels, v.GetNumberValue())
details.SetFloat(bundle.RelationKeyHeightInPixels, v.GetNumberValue())
}
if largest.Meta != nil {
details.Set(bundle.RelationKeyName, strings.TrimSuffix(largest.Name, filepath.Ext(largest.Name)))
details.Set(bundle.RelationKeyFileExt, strings.TrimPrefix(filepath.Ext(largest.Name), "."))
details.Set(bundle.RelationKeyFileMimeType, largest.Media)
details.Set(bundle.RelationKeySizeInBytes, float64(largest.Size_))
details.Set(bundle.RelationKeyAddedDate, float64(largest.Added))
details.SetString(bundle.RelationKeyName, strings.TrimSuffix(largest.Name, filepath.Ext(largest.Name)))
details.SetString(bundle.RelationKeyFileExt, strings.TrimPrefix(filepath.Ext(largest.Name), "."))
details.SetString(bundle.RelationKeyFileMimeType, largest.Media)
details.SetFloat(bundle.RelationKeySizeInBytes, float64(largest.Size_))
details.SetFloat(bundle.RelationKeyAddedDate, float64(largest.Added))
}
if !imageExif.Created.IsZero() {
details.Set(bundle.RelationKeyCreatedDate, float64(imageExif.Created.Unix()))
details.SetFloat(bundle.RelationKeyCreatedDate, float64(imageExif.Created.Unix()))
}
/*if exif.Latitude != 0.0 {
details.Set("latitude", pbtypes.Float64(exif.Latitude))
@ -211,27 +211,27 @@ func (i *image) Details(ctx context.Context) (*domain.Details, error) {
details.Set("longitude", pbtypes.Float64(exif.Longitude))
}*/
if imageExif.CameraModel != "" {
details.Set(bundle.RelationKeyCamera, imageExif.CameraModel)
details.SetString(bundle.RelationKeyCamera, imageExif.CameraModel)
}
if imageExif.ExposureTime != "" {
details.Set(bundle.RelationKeyExposure, imageExif.ExposureTime)
details.SetString(bundle.RelationKeyExposure, imageExif.ExposureTime)
}
if imageExif.FNumber != 0 {
details.Set(bundle.RelationKeyFocalRatio, imageExif.FNumber)
details.SetFloat(bundle.RelationKeyFocalRatio, imageExif.FNumber)
}
if imageExif.ISO != 0 {
details.Set(bundle.RelationKeyCameraIso, float64(imageExif.ISO))
details.SetFloat(bundle.RelationKeyCameraIso, float64(imageExif.ISO))
}
if imageExif.Description != "" {
// use non-empty image description as an image name, because it much uglier to use file names for objects
details.Set(bundle.RelationKeyName, imageExif.Description)
details.SetString(bundle.RelationKeyName, imageExif.Description)
}
if imageExif.Artist != "" {
artistName, artistURL := unpackArtist(imageExif.Artist)
details.Set(bundle.RelationKeyMediaArtistName, artistName)
details.SetString(bundle.RelationKeyMediaArtistName, artistName)
if artistURL != "" {
details.Set(bundle.RelationKeyMediaArtistURL, artistURL)
details.SetString(bundle.RelationKeyMediaArtistURL, artistURL)
}
}
return details, nil

View file

@ -25,7 +25,6 @@ import (
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/space"
"github.com/anyproto/anytype-heart/util/badgerhelper"
"github.com/anyproto/anytype-heart/util/pbtypes"
)
type observerService interface {
@ -191,7 +190,7 @@ func (s *ownProfileSubscription) handleOwnProfileDetails(profileDetails *domain.
bundle.RelationKeyIconImage,
} {
if v, ok := profileDetails.TryString(key); ok {
s.details.Set(key, v)
s.details.SetString(key, v)
}
}
identityProfile := s.prepareIdentityProfile()
@ -232,7 +231,7 @@ func (s *ownProfileSubscription) handleGlobalNameUpdate(globalName string) {
if s.details == nil {
s.details = domain.NewDetails()
}
s.details.Set(bundle.RelationKeyGlobalName, pbtypes.String(globalName))
s.details.SetString(bundle.RelationKeyGlobalName, globalName)
identityProfile := s.prepareIdentityProfile()
s.detailsLock.Unlock()

View file

@ -6,7 +6,6 @@ import (
"github.com/anyproto/anytype-heart/core/domain"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
"github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
"github.com/anyproto/anytype-heart/util/pbtypes"
)
func InjectsSyncDetails(details *domain.Details, status domain.ObjectSyncStatus, syncError domain.SyncError) *domain.Details {
@ -14,13 +13,13 @@ func InjectsSyncDetails(details *domain.Details, status domain.ObjectSyncStatus,
details = domain.NewDetails()
}
if !details.Has(bundle.RelationKeySyncStatus) {
details.Set(bundle.RelationKeySyncStatus, pbtypes.Int64(int64(status)))
details.SetInt64(bundle.RelationKeySyncStatus, int64(status))
}
if !details.Has(bundle.RelationKeySyncDate) {
details.Set(bundle.RelationKeySyncDate, pbtypes.Int64(time.Now().Unix()))
details.SetInt64(bundle.RelationKeySyncDate, time.Now().Unix())
}
if !details.Has(bundle.RelationKeySyncError) {
details.Set(bundle.RelationKeySyncError, pbtypes.Int64(int64(syncError)))
details.SetInt64(bundle.RelationKeySyncError, int64(syncError))
}
return details
}

View file

@ -211,9 +211,9 @@ func (u *syncStatusUpdater) updateObjectDetails(syncStatusDetails *syncStatusDet
if fileStatus, ok := details.TryFloat(bundle.RelationKeyFileBackupStatus); ok {
status, syncError = getSyncStatusForFile(status, syncError, filesyncstatus.Status(int(fileStatus)))
}
details.Set(bundle.RelationKeySyncStatus, pbtypes.Int64(int64(status)))
details.Set(bundle.RelationKeySyncError, pbtypes.Int64(int64(syncError)))
details.Set(bundle.RelationKeySyncDate, pbtypes.Int64(time.Now().Unix()))
details.SetInt64(bundle.RelationKeySyncStatus, int64(status))
details.SetInt64(bundle.RelationKeySyncError, int64(syncError))
details.SetInt64(bundle.RelationKeySyncDate, time.Now().Unix())
return details, true, nil
})
})

View file

@ -468,7 +468,7 @@ func (s *dsObjectStore) FTSearch() ftsearch.FTSearch {
func (s *dsObjectStore) getObjectInfo(ctx context.Context, spaceID string, id string) (*database.ObjectInfo, error) {
details, err := s.sourceService.DetailsFromIdBasedSource(id)
if err == nil {
details.Set(bundle.RelationKeyId, id)
details.SetString(bundle.RelationKeyId, id)
return &database.ObjectInfo{
Id: id,
Details: details,

View file

@ -90,7 +90,7 @@ func (s *dsObjectStore) getInjectedResults(details *domain.Details, score float6
detailsCopy := rec.Details.ShallowCopy()
// set the same score as original object
detailsCopy.Set(database.RecordScoreField, score)
detailsCopy.SetFloat(database.RecordScoreField, score)
injectedResults = append(injectedResults, database.Record{
Details: detailsCopy,
Meta: metaInj,
@ -183,8 +183,8 @@ func (s *dsObjectStore) QueryFromFulltext(results []database.FulltextResult, par
log.Errorf("QueryByIds failed to GetDetailsFromIdBasedSource id: %s", res.Path.ObjectId)
continue
}
details.Set(bundle.RelationKeyId, res.Path.ObjectId)
details.Set(database.RecordScoreField, res.Score)
details.SetString(bundle.RelationKeyId, res.Path.ObjectId)
details.SetFloat(database.RecordScoreField, res.Score)
rec := database.Record{Details: details}
if params.FilterObj == nil || params.FilterObj.FilterObject(rec.Details) {
resultObjectMap[res.Path.ObjectId] = struct{}{}
@ -203,7 +203,7 @@ func (s *dsObjectStore) QueryFromFulltext(results []database.FulltextResult, par
log.Errorf("QueryByIds failed to extract details: %s", res.Path.ObjectId)
continue
}
details.Set(database.RecordScoreField, res.Score)
details.SetFloat(database.RecordScoreField, res.Score)
rec := database.Record{Details: details}
if params.FilterObj == nil || params.FilterObj.FilterObject(rec.Details) {
@ -469,7 +469,7 @@ func (s *dsObjectStore) QueryByID(ids []string) (records []database.Record, err
log.Errorf("QueryByIds failed to GetDetailsFromIdBasedSource id: %s", id)
continue
}
details.Set(bundle.RelationKeyId, id)
details.SetString(bundle.RelationKeyId, id)
records = append(records, database.Record{Details: details})
continue
}

View file

@ -26,7 +26,7 @@ func (s *dsObjectStore) UpdateObjectDetails(ctx context.Context, id string, deta
return fmt.Errorf("empty details")
}
// Ensure ID is set
details.Set(bundle.RelationKeyId, id)
details.SetString(bundle.RelationKeyId, id)
arena := s.arenaPool.Get()
@ -58,7 +58,7 @@ func (s *dsObjectStore) migrateLocalDetails(objectId string, details *domain.Det
}
for k, v := range existingLocalDetails.Fields {
if ok := details.Has(domain.RelationKey(k)); !ok {
details.Set(domain.RelationKey(k), pbtypes.AnyToProto(v))
details.SetProtoValue(domain.RelationKey(k), v)
}
}
return true
@ -125,7 +125,7 @@ func (s *dsObjectStore) UpdatePendingLocalDetails(id string, proc func(details *
}
return txn.Commit()
}
newDetails.Set(bundle.RelationKeyId, id)
newDetails.SetString(bundle.RelationKeyId, id)
jsonVal := domain.ProtoToJson(arena, newDetails)
_, err = s.pendingDetails.UpsertOne(txn.Context(), jsonVal)
if err != nil {
@ -166,7 +166,7 @@ func (s *dsObjectStore) ModifyObjectDetails(id string, proc func(details *domain
return nil, false, nil
}
// Ensure ID is set
newDetails.Set(bundle.RelationKeyId, id)
newDetails.SetString(bundle.RelationKeyId, id)
jsonVal := domain.ProtoToJson(arena, newDetails)
diff, err := pbtypes.DiffJson(val, jsonVal)
@ -207,7 +207,7 @@ func (s *dsObjectStore) updateObjectLinks(ctx context.Context, id string, links
func (s *dsObjectStore) sendUpdatesToSubscriptions(id string, details *domain.Details) {
detCopy := details.ShallowCopy()
detCopy.Set(bundle.RelationKeyId, id)
detCopy.SetString(bundle.RelationKeyId, id)
s.RLock()
defer s.RUnlock()
if s.onChangeCallback != nil {

View file

@ -146,9 +146,9 @@ func buildDiffDetails(origin, current *domain.Details) *domain.Details {
currentList := current.GetStringList(bundle.RelationKeyTargetObjectType)
missedInCurrent, _ := lo.Difference(origin.GetStringList(bundle.RelationKeyTargetObjectType), currentList)
currentList = append(currentList, missedInCurrent...)
value = pbtypes.StringList(currentList)
value = currentList
}
details.Set(key, value)
details.SetUnsafe(key, value)
return true
})
return details

View file

@ -62,18 +62,18 @@ func (s *Set) IsEmpty() bool {
}
func PutToDetails(details *domain.Details, flags []*model.InternalFlag) *domain.Details {
ints := make([]int, 0, len(flags))
raw := make([]float64, 0, len(flags))
for _, f := range flags {
ints = append(ints, int(f.Value))
raw = append(raw, float64(f.Value))
}
return putToDetails(details, ints)
return putToDetails(details, raw)
}
func putToDetails(details *domain.Details, flags []int) *domain.Details {
func putToDetails(details *domain.Details, flags []float64) *domain.Details {
if details == nil {
details = domain.NewDetails()
}
details.Set(relationKey, flags)
details.SetFloatList(relationKey, flags)
return details
}