1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00

Merge pull request #2456 from anyproto/go-5727-subscriptions-improve-lock-contention

GO-5727: Subscriptions: improve lock contention
This commit is contained in:
Sergey 2025-05-28 18:14:07 +02:00 committed by GitHub
commit 4366b74f47
Signed by: github
GPG key ID: B5690EEEBB952194

View file

@ -225,10 +225,14 @@ func (s *service) SubscribeGroups(req SubscribeGroupsRequest) (*pb.RpcObjectGrou
func (s *service) Unsubscribe(subIds ...string) (err error) {
s.lock.Lock()
subs := make([]*spaceSubscriptions, 0, len(s.spaceSubs))
for _, spaceSub := range s.spaceSubs {
err = errors.Join(spaceSub.Unsubscribe(subIds...))
subs = append(subs, spaceSub)
}
s.lock.Unlock()
for _, spaceSub := range subs {
err = errors.Join(spaceSub.Unsubscribe(subIds...))
}
return err
}
@ -614,9 +618,6 @@ type SubscribeGroupsRequest struct {
func (s *spaceSubscriptions) SubscribeGroups(req SubscribeGroupsRequest) (*pb.RpcObjectGroupsSubscribeResponse, error) {
subId := ""
s.m.Lock()
defer s.m.Unlock()
q := database.Query{
Filters: req.Filters,
}
@ -678,6 +679,9 @@ func (s *spaceSubscriptions) SubscribeGroups(req SubscribeGroupsRequest) (*pb.Rp
subId = bson.NewObjectId().Hex()
}
s.m.Lock()
defer s.m.Unlock()
var sub subscription
if colObserver != nil {
sub = s.newCollectionGroupSub(subId, domain.RelationKey(req.RelationKey), flt, groups, colObserver)