From 0655c4175a7ca7d2b128bbbc6490b35bc2b29c66 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Wed, 30 Dec 2015 15:04:42 -0500 Subject: [PATCH] Reduce repeated attempts to validate XML Sitemap URL once successful - If XML Sitemap URL is valid, it is not checked again for at least 1 hour, or until the next time the Auto-Cache Engine runs (every 15 minutes by default). - If XML Sitemap URL is invalid, it is checked repeatedly (every `admin_init`) until it becomes valid. - If XML Sitemap URL changes, it is checked immediately. - If the Auto-Cache Engine encounters an error with the primary XML Sitemap URL while it's running, the error notice is displayed and it is checked repeatedly (every `admin_init`). - When saving the plugin options, the XML Sitemap URL is always validated once (assuming the Auto-Cache Engine is enabled and there is an XML Sitemap URL to validate). See websharks/zencache#643 --- src/includes/classes/Actions.php | 3 +++ src/includes/closures/Plugin/AutoCacheUtils.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/includes/classes/Actions.php b/src/includes/classes/Actions.php index 6b280fe3..05cb1d94 100644 --- a/src/includes/classes/Actions.php +++ b/src/includes/classes/Actions.php @@ -556,6 +556,9 @@ protected function saveOptions($args) $args = $this->plugin->trimDeep(stripslashes_deep((array) $args)); $this->plugin->updateOptions($args); // Save/update options. + // Ensures `autoCacheMaybeClearPrimaryXmlSitemapError()` always validates the XML Sitemap when saving options (when applicable) + delete_transient(GLOBAL_NS.'-'.md5($this->plugin->options['auto_cache_sitemap_url'])); + $redirect_to = self_admin_url('/admin.php'); // Redirect preparations. $query_args = array('page' => GLOBAL_NS, GLOBAL_NS.'_updated' => '1'); diff --git a/src/includes/closures/Plugin/AutoCacheUtils.php b/src/includes/closures/Plugin/AutoCacheUtils.php index e0723030..6d39399f 100644 --- a/src/includes/closures/Plugin/AutoCacheUtils.php +++ b/src/includes/closures/Plugin/AutoCacheUtils.php @@ -96,6 +96,10 @@ if (!$self->options['auto_cache_sitemap_url']) { return; // Nothing to do. } + if(($last_checked = get_transient(GLOBAL_NS.'-'.md5($self->options['auto_cache_sitemap_url']))) && (time() <= ((int)$last_checked + HOUR_IN_SECONDS))) { + $self->dismissMainNotice('xml_sitemap_missing'); // Previous error was fixed; we only create transient when Sitemap passes validation + return; // Nothing to do; already checked within the last hour. + } $is_multisite = is_multisite(); // Multisite network? $can_consider_domain_mapping = $is_multisite && $self->canConsiderDomainMapping(); $blog_url = rtrim(network_home_url(''), '/'); @@ -144,12 +148,14 @@ sprintf(__('

Problematic Sitemap URL: %1$s / Diagnostic Report: %2$s', SLUG_TD), esc_html($sitemap), $failure), array('class' => 'error', 'persistent_key' => 'xml_sitemap_missing', 'dismissable' => false) ); + delete_transient(GLOBAL_NS.'-'.md5($self->options['auto_cache_sitemap_url'])); // Ensures that we check the XML Sitemap URL again immediately until the issue is fixed } return false; // Nothing more we can do in this case. } if (!$is_child_blog && !$is_nested_sitemap) { // Any previous problems have been fixed; dismiss any existing failure notice $self->dismissMainNotice('xml_sitemap_missing'); + set_transient(GLOBAL_NS.'-'.md5($self->options['auto_cache_sitemap_url']), time(), WEEK_IN_SECONDS); // Reduce repeated validation attempts. } return true;