[Asterisk-code-review] res pjsip notify: improve realtime performance on CLI comple... (asterisk[16])

George Joseph asteriskteam at digium.com
Mon Oct 29 13:22:53 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10555 )

Change subject: res_pjsip_notify: improve realtime performance on CLI completion on the endpoint
......................................................................

res_pjsip_notify: improve realtime performance on CLI completion on the endpoint

The module 'res_pjsip_notify' inefficiently makes a lot of DB requests
on CLI completion on the endpoint.

For example if there are 10k endpoints the module makes 10k requests
of these 10k records.

Even if a part of the endpoint entered
the module makes the same 10k requests and then filtered them by itself.

This patch gathers endpoints container by prefix
and adds all gathered endpoints to completion at once.

ASTERISK-28137 #close

Change-Id: Ic20024912cc77bf4d3e476c4cd853293c52b254b
---
M res/res_pjsip_notify.c
1 file changed, 17 insertions(+), 17 deletions(-)

Approvals:
  Corey Farrell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c
index 35144fe..81555a0 100644
--- a/res/res_pjsip_notify.c
+++ b/res/res_pjsip_notify.c
@@ -888,30 +888,30 @@
  * \internal
  * \brief Do completion on the endpoint.
  */
-static char *cli_complete_endpoint(const char *word, int state)
+static char *cli_complete_endpoint(const char *word)
 {
-	char *result = NULL;
 	int wordlen = strlen(word);
-	int which = 0;
-
+	struct ao2_container * endpoints;
 	struct ast_sip_endpoint *endpoint;
-	RAII_VAR(struct ao2_container *, endpoints,
-		 ast_sip_get_endpoints(), ao2_cleanup);
+	struct ao2_iterator i;
 
-	struct ao2_iterator i = ao2_iterator_init(endpoints, 0);
+	endpoints = ast_sorcery_retrieve_by_prefix(ast_sip_get_sorcery(),
+		"endpoint", word, wordlen);
+	if (endpoints == NULL) {
+		return NULL;
+	}
+
+	i = ao2_iterator_init(endpoints, 0);
 	while ((endpoint = ao2_iterator_next(&i))) {
-		const char *name = ast_sorcery_object_get_id(endpoint);
-		if (!strncasecmp(word, name, wordlen) && ++which > state) {
-			result = ast_strdup(name);
-		}
-
+		ast_cli_completion_add(
+			ast_strdup(ast_sorcery_object_get_id(endpoint)));
 		ao2_cleanup(endpoint);
-		if (result) {
-			break;
-		}
 	}
 	ao2_iterator_destroy(&i);
-	return result;
+
+	ao2_ref(endpoints, -1);
+
+	return NULL;
 }
 
 /*!
@@ -967,7 +967,7 @@
 		return c;
 	}
 
-	return pos > 4 && !using_uri ? cli_complete_endpoint(word, state) : NULL;
+	return pos > 4 && !using_uri ? cli_complete_endpoint(word) : NULL;
 }
 
 /*!

-- 
To view, visit https://gerrit.asterisk.org/10555
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic20024912cc77bf4d3e476c4cd853293c52b254b
Gerrit-Change-Number: 10555
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181029/b3af61eb/attachment.html>


More information about the asterisk-code-review mailing list