blackstonetech/usfedgov_google_analytics — pull request #9 by pbull (2013-07-30 14:41:52+00:00)
Title: Remove variable_set() and directory scan from hook_init

The usfedgov_google_analytics module contains a variable_set() function that was being called by way of hook_init(), meaning that every page is calling this function. From a performance perspective, variable_set() is an expensive function because it clears the variable cache which puts increased load on the database as the cache is rebuilt on every page load.

Pull request makes the following changes:

* Use of libraries_load() in hook_init were causing the DAP-Gov-Wide-GA-Code-DOT.js file to be loaded on all pages in addition to the file selected in the config. Replacing this with libraries_detect() returns the same array without forcing the loading of that js file.

* Moved the call to usfedgov_google_analytics_gen_array() so it's not triggered by hook_init but instead is only called when the module's admin form is loaded. It's not likely these files are going to change very often so we don't need to scan the library files so frequently.

* Only saving the js_options global if it has changed. No need to call a variable_set() if the value is the same.

* In _usfedgov_google_analytics_load() we remove the call to usfedgov_google_analytics_gen_array() as noted above, and only load a JavaScript file if there is a file selected via the module's config page.