Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory usage on t-shirt cache prime #1085

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions public_html/wp-content/plugins/camptix/addons/field-tshirt.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ public function prime_report_cache() {
'order' => 'DESC',
) );

$i = 0;
foreach ( $sites as $site_id ) {
switch_to_blog( $site_id );

$i++;
$sizes = $this->get_aggregated_sizes();

if ( ! empty( $sizes ) ) {
Expand All @@ -86,8 +87,11 @@ public function prime_report_cache() {
}

restore_current_blog();
// Reset DB query log each time, to reduce memory usage.
self::reset_db_query_log();
// Reset DB query log & object cache every 10 loops, to reduce memory usage.
if ( 0 == $i % 10 ) {
self::reset_db_query_log();
self::reset_local_object_cache();
}
}

update_site_option( 'tix_aggregated_tshirt_sizes', $sizes_by_site );
Expand All @@ -103,6 +107,26 @@ public function reset_db_query_log() {
$wpdb->queries = array();
}

/**
* Reset local WordPress object cache.
*/
public function reset_local_object_cache() {
global $wp_object_cache;

if ( ! is_object( $wp_object_cache ) ) {
return;
}

$wp_object_cache->group_ops = array();
$wp_object_cache->memcache_debug = array();
$wp_object_cache->cache = array();

if ( method_exists( $wp_object_cache, '__remoteset' ) ) {
$wp_object_cache->__remoteset();
}
}


/**
* Get the counts for each shirt size that attendees selected
*
Expand Down
Loading