Skip to content
Closed
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ed7f3a6
First pass at getting data for XML sitemaps from indexables
Oct 31, 2021
0170779
remove more unused code
Oct 31, 2021
56bc0ac
Reinstate min steps
Oct 31, 2021
ff147e9
Bugfixes
Nov 1, 2021
c7e33f0
Intermediate
Nov 2, 2021
cf87f37
Move image inclusion to helper
Nov 2, 2021
c4b0e68
More documentation and cleanup
Nov 2, 2021
3d82a90
Author sitemaps on indexables
Nov 2, 2021
4380b4f
CS
Nov 2, 2021
5bcc14d
Make sure get_index_links uses same parameters as get_sitemap_links
Nov 4, 2021
701582e
Make get_index_links use indexables table as well
Nov 4, 2021
017a9ec
Remove filter out empty terms filters
Nov 4, 2021
91e32b6
Reinstate exclude_taxonomy filter, remove empty authors
Nov 4, 2021
7c2c4a5
Multiple optimizations
Nov 4, 2021
b5d14c4
Make wpseo_sitemap_entry filter consistent
Nov 5, 2021
ce36e4f
Remove no longer used code
Nov 5, 2021
fe461b2
Remove caching mechanism and image parser as we no longer need it
Nov 5, 2021
5480a4f
Fix CS
Nov 5, 2021
0eb2865
Clean up tests
Nov 5, 2021
7263167
Remove more remnants of sitemaps cache
Nov 5, 2021
6265cdf
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into jdv/xml-s…
Nov 5, 2021
7502d9d
Remove query output when debug is on
Nov 5, 2021
9161e74
early return when there are no indexables to check for imageS
Nov 5, 2021
53b02cb
Fix CS
Nov 5, 2021
04a9e74
Further improvements
Nov 23, 2021
a22baa7
add is-protected check, change filter for entries
Nov 30, 2021
45d6d77
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into j…
diedexx Dec 15, 2021
a7d5a4d
Merge branch 'FIX-22-number-of-posts' of https://github.com/Yoast/wor…
diedexx Dec 15, 2021
23f431c
Simplify class reference
diedexx Dec 19, 2021
eb11224
Use noindex query for user sitemap
diedexx Dec 19, 2021
b1b0e33
Remove unused import
diedexx Dec 19, 2021
6228e8c
Don't increment strings
diedexx Dec 19, 2021
c20ed5a
Don't skip the first entry of a page
diedexx Dec 19, 2021
5e71102
Prevent new posts from changing all previous sitemap entries
diedexx Dec 19, 2021
1613398
Initialize dependency in constructor
diedexx Dec 19, 2021
7aa7642
Use noindex query for post-type sitemaps
diedexx Dec 19, 2021
d091f44
Exclude protected posts instead of including them
diedexx Dec 19, 2021
367a3b3
Only add the max lastmod date to the list if the page is incomplete
diedexx Dec 19, 2021
fcc5640
Use new col for determining visiblity
diedexx Dec 19, 2021
ab32b80
Prevent new posts from changing all previous sitemap entries: post-type
diedexx Dec 19, 2021
c52d663
Always exclude user with id 0 from sitemaps
diedexx Dec 19, 2021
381edaa
Use noindex query for term sitemaps
diedexx Dec 19, 2021
49884cb
Prevent new posts from changing all previous sitemap entries: taxonomies
diedexx Dec 19, 2021
0860082
Use global sitemap page/query limit instead of cutting of post sitema…
diedexx Dec 19, 2021
5b431a8
Fix precedence issues in query
diedexx Dec 19, 2021
cff0053
Fix cs
diedexx Dec 20, 2021
63c7848
Merge branch 'FIX-22-number-of-posts' of https://github.com/Yoast/wor…
diedexx Dec 20, 2021
eabcdb8
Merge branch 'FIX-22-number-of-posts' of https://github.com/Yoast/wor…
diedexx Dec 21, 2021
55956a1
Update tests
diedexx Dec 21, 2021
71e4357
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into sitemaps
Dec 28, 2021
ef5fb89
Optimize sitemap index queries
Dec 29, 2021
cc5e067
Fix default value for is_publicly_viewable and move array checks in t…
Dec 30, 2021
3799c03
Merge branch 'FIX-22-number-of-posts' into sitemaps
Dec 30, 2021
890d83a
Restore wpseo_sitemap_urlimages filter
Dec 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions admin/class-admin-user-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@ public function __construct() {
add_action( 'edit_user_profile', [ $this, 'user_profile' ] );
add_action( 'personal_options_update', [ $this, 'process_user_option_update' ] );
add_action( 'edit_user_profile_update', [ $this, 'process_user_option_update' ] );

add_action( 'update_user_meta', [ $this, 'clear_author_sitemap_cache' ], 10, 3 );
}

/**
* Clear author sitemap cache when settings are changed.
*
* @since 3.1
*
* @param int $meta_id The ID of the meta option changed.
* @param int $object_id The ID of the user.
* @param string $meta_key The key of the meta field changed.
*/
public function clear_author_sitemap_cache( $meta_id, $object_id, $meta_key ) {
if ( $meta_key === '_yoast_wpseo_profile_updated' ) {
WPSEO_Sitemaps_Cache::clear( [ 'author' ] );
}
}

/**
Expand Down
3 changes: 0 additions & 3 deletions admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public function __construct() {

add_action( 'admin_init', [ $this, 'map_manage_options_cap' ] );

WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'wpseo' );
WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'home' );

if ( YoastSEO()->helpers->current_page->is_yoast_seo_page() ) {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"Yoast\\WP\\SEO\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=253",
"@putenv YOASTCS_THRESHOLD_WARNINGS=220",
"@putenv YOASTCS_THRESHOLD_ERRORS=244",
"@putenv YOASTCS_THRESHOLD_WARNINGS=198",
"Yoast\\WP\\SEO\\Composer\\Actions::check_cs_thresholds"
],
"check-cs": [
Expand Down
6 changes: 0 additions & 6 deletions inc/class-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ protected function finish_up( $previous_version = null ) {
// Just flush rewrites, always, to at least make them work after an upgrade.
add_action( 'shutdown', 'flush_rewrite_rules' );

// Flush the sitemap cache.
WPSEO_Sitemaps_Cache::clear();

// Make sure all our options always exist - issue #1245.
WPSEO_Options::ensure_options_exist();
}
Expand Down Expand Up @@ -570,9 +567,6 @@ private function upgrade_772() {
private function upgrade_90() {
global $wpdb;

// Invalidate all sitemap cache transients.
WPSEO_Sitemaps_Cache_Validator::cleanup_database();

// Removes all scheduled tasks for hitting the sitemap index.
wp_clear_scheduled_hook( 'wpseo_hit_sitemap_index' );

Expand Down
133 changes: 133 additions & 0 deletions inc/sitemaps/abstract-class-indexable-sitemap-provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\XML_Sitemaps
*/

use Yoast\WP\Lib\Model;

/**
* WPSEO_Indexable_Sitemap_Provider abstract class
*/
abstract class WPSEO_Indexable_Sitemap_Provider implements WPSEO_Sitemap_Provider {

/**
* The indexable repository.
*
* @var Indexable_Repository
*/
private $repository;

/**
* The XML sitemap helper.
*
* @var XML_Sitemap_Helper
*/
private $xml_sitemap_helper;

/**
* Set up object properties for data reuse.
*/
public function __construct() {
$this->repository = YoastSEO()->classes->get( Indexable_Repository::class );
$this->xml_sitemap_helper = YoastSEO()->helpers->xml_sitemap;
}

/**
* Retrieves the links for the sitemap.
*
* @param int $max_entries Entries per sitemap.
*
* @return array
*/
public function get_index_links( $max_entries ) {
global $wpdb;

$query = $this->repository
->query_where_noindex( false, $this->get_object_type() )
->select( 'id' )
->where( 'is_publicly_viewable', true )
->order_by_asc( 'object_sub_type' )
->order_by_asc( 'object_last_modified' );

$excluded_object_ids = $this->get_excluded_object_ids();
if ( count( $excluded_object_ids ) > 0 ) {
$query->where_not_in( 'object_id', $excluded_object_ids );
}

$table_name = Model::get_table_name( 'Indexable' );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Query is prepared by our ORM.
$raw_query = $wpdb->prepare( $query->get_sql(), $query->get_values() );

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Complex query is not possible without a direct query.
$last_object_per_page = $wpdb->get_results(
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Variables are secure.
$wpdb->prepare(
// This query pulls only every Nth last_modified from the database, resetting row counts when the sub type changes.
"
SELECT i.object_sub_type, i.object_last_modified
FROM $table_name AS i
INNER JOIN (
SELECT id
FROM (
SELECT IF( @previous_sub_type = object_sub_type, @row:=@row+1, @row:=0) AS rownum, @previous_sub_type:=object_sub_type AS previous_sub_type, id
FROM ( $raw_query ) AS sorted, ( SELECT @row:=-1, @previous_sub_type:=null ) AS init
) AS ranked
WHERE rownum MOD %d = 0
) AS subset
ON subset.id = i.id
",
$max_entries
)
// phpcs:enable
);

$index = [];
$page = 1;
foreach ( $last_object_per_page as $index => $object ) {
if ( $this->should_exclude_object_sub_type( $object->object_sub_type ) ) {
continue;
}

$next_object_is_not_same_sub_type = ! ( isset( $last_object_per_page[ ( $index + 1 ) ] ) && $last_object_per_page[ ( $index + 1 ) ] === $object->object_sub_type );
if ( $page === 1 && $next_object_is_not_same_sub_type ) {
$page = '';
}

$index[] = [
'loc' => WPSEO_Sitemaps_Router::get_base_url( $object->object_sub_type . '-sitemap' . $page . '.xml' ),
'lastmod' => $object->object_last_modified,
];

if ( $next_object_is_not_same_sub_type ) {
$page = 1;
}
}

return $index;
}

/**
* Returns the object type for this sitemap.
*
* @return string The object type.
*/
abstract protected function get_object_type();

/**
* Returns a list of all object IDs that should be excluded.
*
* @return int[]
*/
abstract protected function get_excluded_object_ids();

/**
* Whether or not a specific object sub type should be excluded.
*
* @param string $object_sub_type The object sub type.
*
* @return boolean Whether or not it should be excluded.
*/
abstract protected function should_exclude_object_sub_type( $object_sub_type );
}
Loading