@@ -102,7 +102,6 @@ class Connect implements Config, Setup, Notice {
102102 public function __construct ( Plugin $ plugin ) {
103103 $ this ->plugin = $ plugin ;
104104 add_filter ( 'pre_update_option_cloudinary_connect ' , array ( $ this , 'verify_connection ' ) );
105- add_filter ( 'cron_schedules ' , array ( $ this , 'get_status_schedule ' ) ); // phpcs:ignore WordPress.WP.CronInterval
106105 add_action ( 'cloudinary_status ' , array ( $ this , 'check_status ' ) );
107106 add_action ( 'cloudinary_version_upgrade ' , array ( $ this , 'upgrade_connection ' ) );
108107 }
@@ -475,29 +474,13 @@ public function setup() {
475474 }
476475 }
477476
478- /**
479- * Add our every minute schedule.
480- *
481- * @param array $schedules Array of schedules.
482- *
483- * @return array
484- */
485- public function get_status_schedule ( $ schedules ) {
486- $ schedules ['every_minute ' ] = array (
487- 'interval ' => MINUTE_IN_SECONDS ,
488- 'display ' => __ ( 'Every Minute ' , 'cloudinary ' ),
489- );
490-
491- return $ schedules ;
492- }
493-
494477 /**
495478 * Setup Status cron.
496479 */
497480 protected function setup_status_cron () {
498481 if ( false === wp_get_schedule ( 'cloudinary_status ' ) ) {
499482 $ now = current_time ( 'timestamp ' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
500- wp_schedule_event ( $ now + ( MINUTE_IN_SECONDS ), 'every_minute ' , 'cloudinary_status ' );
483+ wp_schedule_event ( $ now + ( MINUTE_IN_SECONDS ), 'hourly ' , 'cloudinary_status ' );
501484 }
502485 }
503486
@@ -514,13 +497,13 @@ public function usage_stats( $refresh = false ) {
514497 if ( ! is_wp_error ( $ stats ) && ! empty ( $ stats ['media_limits ' ] ) ) {
515498 $ stats ['max_image_size ' ] = $ stats ['media_limits ' ]['image_max_size_bytes ' ];
516499 $ stats ['max_video_size ' ] = $ stats ['media_limits ' ]['video_max_size_bytes ' ];
517- set_transient ( self ::META_KEYS ['usage ' ], $ stats , HOUR_IN_SECONDS );
518- update_option ( self ::META_KEYS ['last_usage ' ], $ stats );// Save the last successful call to prevent crashing.
519500 } else {
520501 // Handle error by logging and fetching the last success.
521502 // @todo : log issue.
522503 $ stats = get_option ( self ::META_KEYS ['last_usage ' ] );
523504 }
505+ // Set useage state to the results, either new or the last, to prevent API hits.
506+ set_transient ( self ::META_KEYS ['usage ' ], $ stats , HOUR_IN_SECONDS );
524507 }
525508 $ this ->usage = $ stats ;
526509 }
0 commit comments