Skip to content

Commit

Permalink
Map: Only schedule cron updates for requests with matches
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Dec 11, 2023
1 parent e05dc6e commit 955db50
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mu-plugins/blocks/google-map/inc/event-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ function get_events( string $filter_slug, int $start_timestamp, int $end_timesta
$cacheable = is_cacheable( $facets, $page );

if ( $cacheable ) {
// This has to be called here so that the facets match the ones used to generate the cache.
schedule_filter_cron( $filter_slug, $start_timestamp, $end_timestamp, $facets );

$cache_key = get_cache_key( array_merge(
compact( 'filter_slug', 'start_timestamp', 'end_timestamp' ),
$facets // It's safe to include this because of the logic around `$cacheable`.
Expand Down Expand Up @@ -79,8 +76,12 @@ function get_events( string $filter_slug, int $start_timestamp, int $end_timesta
}

// Store for a day to make sure it never expires before the priming cron job runs.
if ( $cacheable ) {
// There's no point in caching empty values, or scheduling crons to update them.
if ( $cacheable && $events ) {
set_transient( $cache_key, $events, DAY_IN_SECONDS );

// This has to be called here so that the facets match the ones used to generate the cache.
schedule_filter_cron( $filter_slug, $start_timestamp, $end_timestamp, $facets );
}
}

Expand Down

0 comments on commit 955db50

Please sign in to comment.