• Resolved Boone Gorges

    (@boonebgorges)


    Related: https://www.ads-software.com/support/topic/what-does-photocrati_cache_tracker-do/

    On our large WP Multisite installation where a number of sites are running nextgen-gallery, we ran into problems where MySQL was taking up enormous amounts of disk space. We determined that part of the problem is the ‘photocrati_cache_tracker’ “transient manager” system in nextgen-gallery. Specifically, on each site where this option was present, the array in the ‘photocrati_cache_tracker’ option was being filled with many thousands of duplicate entries, which was causing the options tables to get large, thereby causing problems with binary logs as well as the way that the IDB storage engine allocates free space. So, for example, we’d have an option with values like:

        142978 => '2951165530',
        142979 => '2951165530',
        142980 => '2951165530',
        142981 => '2951165530',
        142982 => '2951165530',
        142983 => '2951165530',
        142984 => '2951165530',
        142985 => '2951165530',
        142986 => '2951165530',
        142987 => '2951165530',
        142988 => '2951165530',
        // many thousands of times

    In my investigations of the root cause, I hypothesized that there should *not* be duplicate entries. Looking at the codebase, it seemed that there should be a duplicate check in the _track_key() method: https://plugins.trac.www.ads-software.com/browser/nextgen-gallery/tags/3.35/non_pope/class.photocrati_transient_manager.php#L118

    As such, I made the following change on our installation several weeks ago:

    diff --git a/wp-content/plugins/nextgen-gallery/non_pope/class.photocrati_transient_manager.php b/wp-content/plugins/nextgen-gallery/non_pope/class.photocrati_transient_manager.php
    index 41d0f49f46..70fae00b2e 100644
    --- a/wp-content/plugins/nextgen-gallery/non_pope/class.photocrati_transient_manager.php
    +++ b/wp-content/plugins/nextgen-gallery/non_pope/class.photocrati_transient_manager.php
    @@ -127,7 +127,10 @@ class C_Photocrati_Transient_Manager
                            $id = $parts[1];
                            if (!isset($this->_tracker[$group]))
                                $this->_tracker[$group] = array();
    -                       $this->_tracker[$group][] = $id;
    +
    +                       if ( ! in_array( $id, $this->_tracker[ $group ] ) ) {
    +                               $this->_tracker[$group][] = $id;
    +                       }
                    }
            }

    After clearing out existing caches and running this modification for a few weeks, the problem seems to have gone away: the ‘photocrati_cache_tracker’ option is being populated without duplicates, and we haven’t noticed any negative side-effects.

    We hope your team will consider reviewing this change to see whether they can imagine any bad effects from the proposed change.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Imagely

    (@imagely)

    Hi @boonebgorges,

    Thanks for contacting us. We’ll check with the dev team to see if the code can be improved.

    Our method for flushing transient groups normally works by directly querying the wp_options table based on the option_name column, but that isn’t available when an external object cache is active like memcache or redis.

    For the similar cases, we suggest adding this constant that’d disable the cache tracker entirely:

    define('NGG_DISABLE_PHOTOCRATI_CACHE_TRACKER', true);
    Thread Starter Boone Gorges

    (@boonebgorges)

    Ah, I didn’t quite grasp in my reading that the transient-flushing logic wasn’t necessary for external object caches, which is why I didn’t set the NGG_DISABLE_PHOTOCRATI_CACHE_TRACKER constant to begin with. I’ll explore this with my team.

    My suggested fix should still be worth exploring for sites where no external cache is in place, so I hope you’ll consider it.

    Thanks for the quick response.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Performance fix for ‘photocrati_cache_tracker’ transient cache’ is closed to new replies.