Changeset 5017 for sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php
- Timestamp:
- 02/28/2017 08:29:05 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php
r4871 r5017 56 56 global $wpdb; 57 57 58 $this->log( 'started call #' . did_action( 'owpe_prime_events_cache' ) ); 59 60 if ( did_action( 'owpe_prime_events_cache' ) > 1 ) { 61 $this->log( 'Successive call detected, returning early' ); 62 return; 63 } 64 58 65 $events = $this->fetch_upcoming_events(); 66 67 $this->log( sprintf( 'looping through %d events', count( $events ) ) ); 59 68 60 69 foreach ( $events as $event ) { … … 92 101 $wpdb->replace( self::EVENTS_TABLE, $row_values ); 93 102 } 103 104 $this->log( 'finished job' ); 94 105 } 95 106 … … 246 257 } 247 258 259 $this->log( sprintf( 'returning %d events', count( $events ) ) ); 260 248 261 return $events; 249 262 } … … 407 420 $response = $this->remote_get( $request_url ); 408 421 $body = json_decode( wp_remote_retrieve_body( $response ) ); 422 423 $this->log( 'fetching more events' ); 409 424 410 425 if ( ! empty ( $body->results ) ) { … … 458 473 } 459 474 475 $this->log( sprintf( 'returning %d events', count( $events ) ) ); 476 460 477 return $events; 461 478 } … … 481 498 482 499 while ( '' !== $request_url ) { 500 $this->log( 'fetching more groups' ); 501 483 502 $response = $this->remote_get( $request_url ); 484 503 $body = json_decode( wp_remote_retrieve_body( $response ) ); … … 491 510 $request_url = $body->meta->next; 492 511 } 512 513 $this->log( sprintf( 'returning %d groups', count( $group_ids ) ) ); 493 514 494 515 return $group_ids; … … 512 533 513 534 if ( ! is_wp_error( $response ) ) { 535 $this->log( 'geocode successful' ); 536 514 537 $body = json_decode( wp_remote_retrieve_body( $response ) ); 515 538 … … 517 540 $address = $body->results[0]; 518 541 } 542 } 543 else { 544 $this->log( 'geocode failed' ); 519 545 } 520 546 … … 654 680 } 655 681 682 $this->log( 'sleeping to avoid api rate limit' ); 656 683 sleep( $period ); 684 } 685 686 /** 687 * Log messages to the database 688 * 689 * To avoid storing too much data, the log is reset during each run, and only $limit rows are stored 690 * 691 * @param string $message 692 */ 693 protected function log( $message ) { 694 $limit = 500; 695 696 if ( ! isset( $this->log ) ) { 697 $this->log = array(); 698 } 699 700 if ( count( $this->log ) > $limit ) { 701 wp_die('early return'); 702 return; 703 } 704 705 $backtrace = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, 2 ); 706 707 $this->log[] = sprintf( 708 '%s - %s MB - %s - %s', 709 microtime( true ), 710 number_format( memory_get_usage( true ) / 1024 / 2014, 2 ), 711 $backtrace[1]['function'], 712 $message 713 ); 714 715 if ( $limit === count( $this->log ) ) { 716 $this->log[] = array( 'Reached log limit, assuming some kind of infinite loop. Will not log any more messages.' ); 717 } 718 719 update_option( 'owpe_log', $this->log, false ); 657 720 } 658 721 }
Note: See TracChangeset
for help on using the changeset viewer.