Hello everyone,
I'm working on a project that is within a custom wordpress site/app that is using too much memory. Its a fitness app that tracks staff and teams fitness points/scores. I'm 99% sure the cron job is the issue but not quite sure what's off about it causing this app to use so much memory. There are roughly 300 people using this app and they do at least one exercise per day and input it within their profile. Below is the code for the cron job. Is there anything wrong with this code that would cause this app to use so much memory? As you can see its been modified from every 5 mins to every 30 so it doesn't use so much.
function my_cron_schedules($schedules){
if(!isset($schedules["5min"])){
$schedules["5min"] = array(
'interval' => 5*60,
'display' => __('Once every 5 minutes'));
}
if(!isset($schedules["30min"])){
$schedules["30min"] = array(
'interval' => 30*60,
'display' => __('Once every 30 minutes'));
}
return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');
add_action('thirty_minute_event', 'update_team_avg_points');
function my_activation() {
if ( !wp_next_scheduled( 'thirty_minute_event' ) ) {
wp_schedule_event( current_time( 'timestamp' ), '30min', 'thirty_minute_event');
}
}
add_action('wp', 'my_activation');
function update_team_avg_points() {
// THIS UPDATES TOTAL USER POINTS.
$users = get_users(array(
'blog_id' => 1,
));
foreach($users as $user){
$userPoints = get_all_points_for_user($user->ID);
update_user_meta($user->ID, '_ecfit_user_points', $userPoints);
}
// THIS UPDATES TEAM AVG POINT VALUE.
$staff_teams = ecfit_get_teams( 'staff' );
$apprentice_teams = ecfit_get_teams( '2k2/Contractor/Intern' );
$family_teams = ecfit_get_teams( 'family' );
if($staff_teams){
foreach( $staff_teams as $team ){
$team_points = $team->get_average_points();
$teamId = $team->get_id();
update_post_meta($teamId, '_ecfit_team_avg', $team_points);
}
}
if($apprentice_teams){
foreach( $apprentice_teams as $team ){
$team_points = $team->get_average_points();
$teamId = $team->get_id();
update_post_meta($teamId, '_ecfit_team_avg', $team_points);
}
}
if($family_teams){
foreach( $family_teams as $team ){
$team_points = $team->get_average_points();
$teamId = $team->get_id();
update_post_meta($teamId, '_ecfit_team_avg', $team_points);
}
}
}