Skip to content

Commit

Permalink
FileSync: Prevent status flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
deff7 committed Feb 17, 2025
1 parent cea4b09 commit f1ceda0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 0 additions & 3 deletions core/block/editor/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func (f *File) Init(ctx *smartblock.InitContext) error {
if err != nil {
log.Errorf("failed to ensure file added to sync queue: %v", err)
}
f.AddHook(func(applyInfo smartblock.ApplyInfo) error {
return f.fileObjectService.EnsureFileAddedToSyncQueue(fullId, applyInfo.State.Details())
}, smartblock.HookOnStateRebuild)
}
return nil
}
Expand Down
25 changes: 19 additions & 6 deletions core/files/fileobject/fileindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ import (
"github.com/anyproto/anytype-heart/space"
)

type accountService interface {
MyParticipantId(string) string
}

type indexer struct {
fileService files.Service
spaceService space.Service
objectStore objectstore.ObjectStore
fileService files.Service
spaceService space.Service
objectStore objectstore.ObjectStore
accountService accountService

query database.Query
indexCtx context.Context
Expand All @@ -42,9 +47,10 @@ type indexer struct {

func (s *service) newIndexer() *indexer {
ind := &indexer{
fileService: s.fileService,
spaceService: s.spaceService,
objectStore: s.objectStore,
fileService: s.fileService,
spaceService: s.spaceService,
objectStore: s.objectStore,
accountService: s.accountService,

indexQueue: mb.New[indexRequest](0),
isQueued: make(map[domain.FullID]struct{}),
Expand Down Expand Up @@ -128,6 +134,13 @@ func (ind *indexer) addToQueueFromObjectStore(ctx context.Context) error {
}
for _, rec := range recs {
spaceId := rec.Details.GetString(bundle.RelationKeySpaceId)

// There is no point to index file if the current user is not an owner of the file
myParticipantId := ind.accountService.MyParticipantId(spaceId)
if rec.Details.GetString(bundle.RelationKeyCreator) != myParticipantId {
continue
}

id := domain.FullID{
SpaceID: spaceId,
ObjectID: rec.Details.GetString(bundle.RelationKeyId),
Expand Down
3 changes: 3 additions & 0 deletions core/files/fileobject/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type service struct {
objectStore objectstore.ObjectStore
spaceIdResolver idresolver.Resolver
migrationQueue *persistentqueue.Queue[*migrationItem]
accountService accountService
objectArchiver objectArchiver

indexer *indexer
Expand Down Expand Up @@ -117,6 +118,8 @@ func (s *service) Init(a *app.App) error {
s.spaceIdResolver = app.MustComponent[idresolver.Resolver](a)
s.fileOffloader = app.MustComponent[fileoffloader.Service](a)
s.objectArchiver = app.MustComponent[objectArchiver](a)
s.accountService = app.MustComponent[accountService](a)

cfg := app.MustComponent[configProvider](a)

s.indexer = s.newIndexer()
Expand Down
2 changes: 1 addition & 1 deletion core/syncstatus/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *service) indexFileSyncStatus(fileObjectId string, status filesyncstatus
err := cache.Do(s.objectGetter, fileObjectId, func(sb smartblock.SmartBlock) (err error) {
prevStatus := sb.Details().GetInt64(bundle.RelationKeyFileBackupStatus)
newStatus := int64(status)
if prevStatus == newStatus {
if prevStatus == newStatus || prevStatus == int64(filesyncstatus.Synced) {
return nil
}
st := sb.NewState()
Expand Down

0 comments on commit f1ceda0

Please sign in to comment.