Skip to content

Commit

Permalink
GO-3861 Merge branch 'main' of ssh://github.com/anyproto/anytype-hear…
Browse files Browse the repository at this point in the history
  • Loading branch information
requilence committed Oct 4, 2024
2 parents 7869711 + 1ab48dc commit 80923ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions core/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ type indexer struct {
btHash Hasher
forceFt chan struct{}

mb *mb.MB[clientspace.Space]
lastSpacesSubscription *syncsubscriptions.ObjectSubscription[*types.Struct]
lock sync.Mutex
reindexLogFields []zap.Field
techSpaceId techSpaceIdGetter
spacesPriority []string
spaceReindexQueue *taskmanager.TasksManager
mb *mb.MB[clientspace.Space]

Check failure on line 84 in core/indexer/indexer.go

View workflow job for this annotation

GitHub Actions / lint

field `mb` is unused (unused)
spacesPrioritySubscription *syncsubscriptions.ObjectSubscription[*types.Struct]
lock sync.Mutex
reindexLogFields []zap.Field
techSpaceId techSpaceIdGetter
spacesPriority []string
spaceReindexQueue *taskmanager.TasksManager
}

func (i *indexer) Init(a *app.App) (err error) {
Expand Down Expand Up @@ -132,6 +132,7 @@ func (i *indexer) StartFullTextIndex() (err error) {

func (i *indexer) Close(ctx context.Context) (err error) {
i.componentCancel()
i.spacesPrioritySubscription.Close()
i.spaceReindexQueue.WaitAndClose()
// we need to wait for the ftQueue processing to be finished gracefully. Because we may be in the middle of badger transaction
<-i.ftQueueFinished
Expand Down Expand Up @@ -299,13 +300,13 @@ func (i *indexer) subscribeToSpaces() error {
},
},
}
updatesChan := make(chan []*types.Struct)
go i.spacesSubscriptionChanWatcher(updatesChan)
i.lastSpacesSubscription = syncsubscriptions.NewSubscription(i.subscriptionService, objectReq)
return i.lastSpacesSubscription.Run(updatesChan)
spacePriorityUpdateChan := make(chan []*types.Struct)
go i.spacesPrioritySubscriptionWatcher(spacePriorityUpdateChan)
i.spacesPrioritySubscription = syncsubscriptions.NewSubscription(i.subscriptionService, objectReq)
return i.spacesPrioritySubscription.Run(spacePriorityUpdateChan)
}

func (i *indexer) spacesSubscriptionSetPriority(priority []string) {
func (i *indexer) spacesPriorityUpdate(priority []string) {
techSpaceId := i.techSpaceId.TechSpaceId()
i.lock.Lock()
i.spacesPriority = append([]string{techSpaceId}, slices.DeleteFunc(priority, func(s string) bool {
Expand All @@ -317,13 +318,15 @@ func (i *indexer) spacesSubscriptionSetPriority(priority []string) {
i.spaceReindexQueue.RefreshPriority()
}

func (i *indexer) spacesSubscriptionChanWatcher(ch chan []*types.Struct) {
func (i *indexer) spacesPrioritySubscriptionWatcher(ch chan []*types.Struct) {
for {

Check failure on line 322 in core/indexer/indexer.go

View workflow job for this annotation

GitHub Actions / lint

S1000: should use for range instead of for { select {} } (gosimple)
select {
case <-i.componentCtx.Done():
return
// subscription and chan will be closed on indexer close
case records := <-ch:
i.spacesSubscriptionSetPriority(pbtypes.ExtractString(records, bundle.RelationKeyTargetSpaceId.String(), true))
if records == nil {
return
}
i.spacesPriorityUpdate(pbtypes.ExtractString(records, bundle.RelationKeyTargetSpaceId.String(), true))
}
}
}
Binary file modified util/builtinobjects/data/get_started.zip
Binary file not shown.

0 comments on commit 80923ba

Please sign in to comment.