From 303465af35c13691f989b3400b028a94df1235d4 Mon Sep 17 00:00:00 2001 From: Harkrishn Patro <30795839+hpatro@users.noreply.github.com> Date: Wed, 17 Feb 2021 23:13:50 +0100 Subject: Remove redundant pubsub list to store the patterns. (#8472) Remove redundant pubsub list to store the patterns. --- src/pubsub.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'src/pubsub.c') diff --git a/src/pubsub.c b/src/pubsub.c index 7355e10b9..a7b370d5d 100644 --- a/src/pubsub.c +++ b/src/pubsub.c @@ -124,20 +124,6 @@ void addReplyPubsubPatUnsubscribed(client *c, robj *pattern) { * Pubsub low level API *----------------------------------------------------------------------------*/ -void freePubsubPattern(void *p) { - pubsubPattern *pat = p; - - decrRefCount(pat->pattern); - zfree(pat); -} - -int listMatchPubsubPattern(void *a, void *b) { - pubsubPattern *pa = a, *pb = b; - - return (pa->client == pb->client) && - (equalStringObjects(pa->pattern,pb->pattern)); -} - /* Return the number of channels + patterns a client is subscribed to. */ int clientSubscriptionsCount(client *c) { return dictSize(c->pubsub_channels)+ @@ -212,18 +198,13 @@ int pubsubSubscribePattern(client *c, robj *pattern) { if (listSearchKey(c->pubsub_patterns,pattern) == NULL) { retval = 1; - pubsubPattern *pat; listAddNodeTail(c->pubsub_patterns,pattern); incrRefCount(pattern); - pat = zmalloc(sizeof(*pat)); - pat->pattern = getDecodedObject(pattern); - pat->client = c; - listAddNodeTail(server.pubsub_patterns,pat); /* Add the client to the pattern -> list of clients hash table */ - de = dictFind(server.pubsub_patterns_dict,pattern); + de = dictFind(server.pubsub_patterns,pattern); if (de == NULL) { clients = listCreate(); - dictAdd(server.pubsub_patterns_dict,pattern,clients); + dictAdd(server.pubsub_patterns,pattern,clients); incrRefCount(pattern); } else { clients = dictGetVal(de); @@ -241,19 +222,14 @@ int pubsubUnsubscribePattern(client *c, robj *pattern, int notify) { dictEntry *de; list *clients; listNode *ln; - pubsubPattern pat; int retval = 0; incrRefCount(pattern); /* Protect the object. May be the same we remove */ if ((ln = listSearchKey(c->pubsub_patterns,pattern)) != NULL) { retval = 1; listDelNode(c->pubsub_patterns,ln); - pat.client = c; - pat.pattern = pattern; - ln = listSearchKey(server.pubsub_patterns,&pat); - listDelNode(server.pubsub_patterns,ln); /* Remove the client from the pattern -> clients list hash table */ - de = dictFind(server.pubsub_patterns_dict,pattern); + de = dictFind(server.pubsub_patterns,pattern); serverAssertWithInfo(c,NULL,de != NULL); clients = dictGetVal(de); ln = listSearchKey(clients,c); @@ -262,7 +238,7 @@ int pubsubUnsubscribePattern(client *c, robj *pattern, int notify) { if (listLength(clients) == 0) { /* Free the list and associated hash entry at all if this was * the latest client. */ - dictDelete(server.pubsub_patterns_dict,pattern); + dictDelete(server.pubsub_patterns,pattern); } } /* Notify the client */ @@ -329,7 +305,7 @@ int pubsubPublishMessage(robj *channel, robj *message) { } } /* Send to clients listening to matching channels */ - di = dictGetIterator(server.pubsub_patterns_dict); + di = dictGetIterator(server.pubsub_patterns); if (di) { channel = getDecodedObject(channel); while((de = dictNext(di)) != NULL) { @@ -502,7 +478,7 @@ NULL } } else if (!strcasecmp(c->argv[1]->ptr,"numpat") && c->argc == 2) { /* PUBSUB NUMPAT */ - addReplyLongLong(c,listLength(server.pubsub_patterns)); + addReplyLongLong(c,dictSize(server.pubsub_patterns)); } else { addReplySubcommandSyntaxError(c); } -- cgit v1.2.1