Skip to content

Commit

Permalink
Reduce repeated attempts to validate XML Sitemap URL once successful
Browse files Browse the repository at this point in the history
  - 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 wpsharks/comet-cache#643
  • Loading branch information
raamdev committed Dec 30, 2015
1 parent 097f806 commit 0655c41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/includes/classes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
6 changes: 6 additions & 0 deletions src/includes/closures/Plugin/AutoCacheUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(''), '/');
Expand Down Expand Up @@ -144,12 +148,14 @@
sprintf(__('<p><strong>Problematic Sitemap URL:</strong> <a href="%1$s" target="_blank">%1$s</a> / <strong>Diagnostic Report:</strong> %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;
Expand Down

0 comments on commit 0655c41

Please sign in to comment.