[Asterisk-code-review] sounds index: Avoid repeatedly reindexing. (asterisk[master])

Corey Farrell asteriskteam at digium.com
Wed Dec 6 14:59:28 CST 2017


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7454


Change subject: sounds_index: Avoid repeatedly reindexing.
......................................................................

sounds_index: Avoid repeatedly reindexing.

The sounds index is rebuilt each time a format is registered or
unregistered.  This causes the index to be repeatedly rebuilt during
startup and shutdown.

This patch significantly reduces the work done by ignoring format
register / unregister during startup or shutdown.  The sounds index is
rebuilt once when asterisk is fully booted.  During shutdown we simply
destroy the index when appropriate.

Change-Id: I585fd6ee04200612ab1490dc804f76805f89cf0a
---
M main/sounds_index.c
1 file changed, 29 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/7454/1

diff --git a/main/sounds_index.c b/main/sounds_index.c
index c7f9f4d..2528d4b 100644
--- a/main/sounds_index.c
+++ b/main/sounds_index.c
@@ -285,6 +285,32 @@
 static void format_update_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_message *message)
 {
+	/* Instead of reindexing after each format module loads we defer until FullyBooted.
+	 * During shutdown we just don't bother, leave it to sounds_cleanup. */
+	if (ast_fully_booted && !ast_shutting_down()) {
+		ast_sounds_reindex();
+	}
+}
+
+/*! \brief Event callback which fires sounds reindex when the system is fully booted */
+static void sounds_fullybooted_reindex(void *data, struct stasis_subscription *sub,
+	struct stasis_message *message)
+{
+	struct ast_json_payload *payload;
+	const char *type;
+
+	if (stasis_message_type(message) != ast_manager_get_generic_type()) {
+		return;
+	}
+
+	payload = stasis_message_data(message);
+	type = ast_json_string_get(ast_json_object_get(payload->json, "type"));
+
+	if (strcmp(type, "FullyBooted")) {
+		return;
+	}
+
+	stasis_unsubscribe(sub);
 	ast_sounds_reindex();
 }
 
@@ -292,9 +318,12 @@
 {
 	int res = 0;
 	sounds_index = NULL;
+
 	if (ast_sounds_reindex()) {
 		return -1;
 	}
+	stasis_subscribe_pool(ast_manager_get_topic(), sounds_fullybooted_reindex, NULL);
+
 	res |= ast_cli_register_multiple(cli_sounds, ARRAY_LEN(cli_sounds));
 
 	sounds_system_router = stasis_message_router_create(ast_system_topic());

-- 
To view, visit https://gerrit.asterisk.org/7454
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I585fd6ee04200612ab1490dc804f76805f89cf0a
Gerrit-Change-Number: 7454
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171206/0dea738e/attachment-0001.html>


More information about the asterisk-code-review mailing list