From 6122f1c450846584eedf614551de0c97da305b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Sun, 28 Feb 2021 13:11:18 +0100 Subject: Shared reusable client for RM_Call() (#8516) A single client pointer is added in the server struct. This is initialized by the first RM_Call() and reused for every subsequent RM_Call() except if it's already in use, which means that it's not used for (recursive) module calls to modules. For these, a new "fake" client is created each time. Other changes: * Avoid allocating a dict iterator in pubsubUnsubscribeAllChannels when not needed --- src/pubsub.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/pubsub.c') diff --git a/src/pubsub.c b/src/pubsub.c index a7b370d5d..5f7335bbe 100644 --- a/src/pubsub.c +++ b/src/pubsub.c @@ -250,18 +250,20 @@ int pubsubUnsubscribePattern(client *c, robj *pattern, int notify) { /* Unsubscribe from all the channels. Return the number of channels the * client was subscribed to. */ int pubsubUnsubscribeAllChannels(client *c, int notify) { - dictIterator *di = dictGetSafeIterator(c->pubsub_channels); - dictEntry *de; int count = 0; + if (dictSize(c->pubsub_channels) > 0) { + dictIterator *di = dictGetSafeIterator(c->pubsub_channels); + dictEntry *de; - while((de = dictNext(di)) != NULL) { - robj *channel = dictGetKey(de); + while((de = dictNext(di)) != NULL) { + robj *channel = dictGetKey(de); - count += pubsubUnsubscribeChannel(c,channel,notify); + count += pubsubUnsubscribeChannel(c,channel,notify); + } + dictReleaseIterator(di); } /* We were subscribed to nothing? Still reply to the client. */ if (notify && count == 0) addReplyPubsubUnsubscribed(c,NULL); - dictReleaseIterator(di); return count; } -- cgit v1.2.1