Title: Possible code improvement, performance
Last modified: September 1, 2016

---

# Possible code improvement, performance

 *  [aamche](https://wordpress.org/support/users/aamche/)
 * (@aamche)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/possible-code-improvement-performance/)
 * File: /lib/Advman/Dal.php
    Line: 43 (approx)
 * These lines if never propagated with a value, default to an empty value, that
   always forces a save of an empty value, which will be updated next time with 
   another empty value.
 * Essentially adding unnecessary load or in my case 0.5 seconds, which could be
   avoided.
 * # This code always wants to save
 *     ```
       // Get networks data
       $d = get_option('plugin_advman_networks');
       if (empty($d)) {
           $d = array();
           $save = true;
       }
       $data['networks'] = $d;
       ```
   
 * # Save functions (update_option) are expensive in terms of load, causing the 
   0.5s lag
 *     ```
       if ($save) {
       	update_option('plugin_advman_settings', $data['settings']);
       	update_option('plugin_advman_ads', $data['ads']);
       	update_option('plugin_advman_networks', $data['networks']);
       	update_option('plugin_advman_stats', $data['stats']);
       }
       ```
   
 * # In my case I made it ignore empty arrays. I also moved the update_options in
   to the actually save trigger, as it was calling update_option 4 times when just
   the stats were updated, thus 3 times not needed.
 *     ```
       // Get networks data
       $d = get_option('plugin_advman_networks');
       if (empty($d) && !is_array($d)) {
       	$d = array();
       	update_option('plugin_advman_networks', $d);
       }
       $data['networks'] = $d;
       ```
   
 * Hope that helps, let me know if I can help more.
 * [https://wordpress.org/plugins/advertising-manager/](https://wordpress.org/plugins/advertising-manager/)

The topic ‘Possible code improvement, performance’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/advertising-manager.svg)
 * [Advertising Manager](https://wordpress.org/plugins/advertising-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advertising-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advertising-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/advertising-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advertising-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advertising-manager/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [aamche](https://wordpress.org/support/users/aamche/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/possible-code-improvement-performance/)
 * Status: not resolved