fix(server): limit implicit large group subscription meta
This commit is contained in:
+23
-1
@@ -202,6 +202,8 @@ const (
|
||||
StopRehashing
|
||||
)
|
||||
|
||||
const implicitGroupSubSelfOnlyThreshold = 1000
|
||||
|
||||
// Topic shutdown
|
||||
type shutDown struct {
|
||||
// Channel to report back completion of topic shutdown. Could be nil
|
||||
@@ -2894,7 +2896,6 @@ func (t *Topic) replyGetDesc(sess *Session, asUid types.Uid, _ bool, opts *MsgGe
|
||||
if t.cat == types.TopicCatGrp {
|
||||
desc.IsChan = t.isChan
|
||||
desc.SubCnt = t.subCnt
|
||||
logs.Info.Println("replyGetDesc: grp topic", t.name, "subs", t.subCnt)
|
||||
}
|
||||
|
||||
if ifUpdated {
|
||||
@@ -3353,6 +3354,12 @@ func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, authLevel auth.Level
|
||||
// Channel subscribers are using chnXXX topic name rather than grpXXX.
|
||||
topicName = msg.Original
|
||||
}
|
||||
if req = t.limitImplicitLargeGroupSubQuery(req, asUid, msg); req != nil {
|
||||
ifModified = time.Time{}
|
||||
if req.IfModifiedSince != nil {
|
||||
ifModified = *req.IfModifiedSince
|
||||
}
|
||||
}
|
||||
// Include sub.Public.
|
||||
if ifModified.IsZero() {
|
||||
// No cache management. Skip deleted subscriptions.
|
||||
@@ -3557,6 +3564,21 @@ func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, authLevel auth.Level
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Topic) limitImplicitLargeGroupSubQuery(req *MsgGetOpts, asUid types.Uid, msg *ClientComMessage) *MsgGetOpts {
|
||||
if t.cat != types.TopicCatGrp || msg == nil || msg.Sub == nil || t.subCnt < implicitGroupSubSelfOnlyThreshold {
|
||||
return req
|
||||
}
|
||||
if req != nil && (req.User != "" || req.Topic != "" || req.Limit != 0 || req.IfModifiedSince != nil) {
|
||||
return req
|
||||
}
|
||||
limited := &MsgGetOpts{}
|
||||
if req != nil {
|
||||
*limited = *req
|
||||
}
|
||||
limited.User = asUid.UserId()
|
||||
return limited
|
||||
}
|
||||
|
||||
// replySetSub is a response to new subscription request or an update to a subscription {set.sub}:
|
||||
// update topic metadata cache, save/update subs, reply to the caller as {ctrl} message,
|
||||
// generate a presence notification, if appropriate.
|
||||
|
||||
Reference in New Issue
Block a user