-
Notifications
You must be signed in to change notification settings - Fork 902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create API endpoints for SEO scores #21829
Create API endpoints for SEO scores #21829
Conversation
Pull Request Test Coverage Report for Build 84c653c5441f79891f1b0a96f89b4fc3eb384333Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
@leonidasmi For the query with taxonomy filtering, can you try if this version is producing the same output and whether it is more efficient: SELECT
SUM(I.primary_focus_keyword_score < 41) AS needs_improvement,
SUM(I.primary_focus_keyword_score BETWEEN 41 AND 69) AS ok,
SUM(I.primary_focus_keyword_score >= 70) AS good,
SUM(I.primary_focus_keyword_score IS NULL) AS not_analyzed
FROM %i AS I
INNER JOIN %i AS tr ON I.object_id = tr.object_id
INNER JOIN %i AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE (I.post_status = 'publish' OR I.post_status IS NULL)
AND I.object_type = 'post'
AND I.object_sub_type IN (%s)
AND tt.term_id = %d
AND tt.taxonomy = %s
I haven't tested it yet for lack of environment right now, so double-check if everything is as expected. |
Hmm, you might need to be more explicit to make sure the expressions are compatible across all supported DB versions. SELECT
SUM(CASE WHEN I.primary_focus_keyword_score < 41 THEN 1 ELSE 0 END) AS needs_improvement,
SUM(CASE WHEN I.primary_focus_keyword_score >= 41
AND I.primary_focus_keyword_score < 70 THEN 1 ELSE 0 END) AS ok,
SUM(CASE WHEN I.primary_focus_keyword_score >= 70 THEN 1 ELSE 0 END) AS good,
SUM(CASE WHEN I.primary_focus_keyword_score IS NULL THEN 1 ELSE 0 END) AS not_analyzed
FROM %i AS I
INNER JOIN %i AS tr ON I.object_id = tr.object_id
INNER JOIN %i AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE (I.post_status = 'publish' OR I.post_status IS NULL)
AND I.object_type = 'post'
AND I.object_sub_type IN (%s)
AND tt.term_id = %d
AND tt.taxonomy = %s |
@schlessera I compared the one you shared with the one I already have and while they produce the same results, they also have similar, if not identical, performance. Specifically, their I then tried to tinker with my Which means that we can simplify the query likeso:
|
Context
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
wpseo_{$content_type}_filtering_taxonomy
filter or because it's a hardoced filtering pair, described in this PR)query_var
, there will be noView
URLs returned, because there can't be a URL that filters the CPT page on that taxonomy. In those cases, we will have noView
buttons in the UITest instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Note: We're going to use POSTMAN to test the API endpoint, so use this post to learn how to authenticate.
For posts and categories:
primary_focus_keyword_score
, to have a view on what to expect/wp-json/yoast/v1/seo_scores?contentType=post
and confirm that you get a response similar to the below, with the amounts representing what you have in the database:primary_focus_keyword_score
over 70, 1 post withprimary_focus_keyword_score
between 41 and 70, 2 posts with under 40 and 1 post without keyphrase.primary_focus_keyword_score
over 70 into a draft and repeat the request -> you should get one lessamount
in thegood
object.primary_focus_keyword_score
over 70 into anoindexed
post and repeat the request -> you should get one lessamount
in thegood
object and when visiting the link you get the same amount of posts in the filtered posts page./wp-json/yoast/v1/seo_scores?contentType=post&taxonomy=category&term=<TERM_ID>
(replaceTERM_ID
with the correct term ID)/wp-json/yoast/v1/seo_scores?contentType=product&taxonomy=product_cat&term=<TERM_ID>
- pay extra focus on the links to confirm that they get you to the right filtered state in the products page/wp-json/yoast/v1/seo_scores?contentType=<CPT_NAME>&taxonomy=<TAX_NAME>&term=<TERM_ID>
- pay extra focus on the links to confirm that they get you to the right filtered state in the CPT pageAdded filter via hook, for a taxonomy with custom REST API URL
in order to be able to create a CPT and connect it to a filtering taxonomy.For when SEO scores are at the end of the ranges:
40
,41
,70
,71
, to make sure they are categorized asbad
,ok
,ok
andgood
respectivelyprimary_focus_keyword
to to40
,41
,70
,71
._yoast_wpseo_linkdex
column to the same/wp-json/yoast/v1/seo_scores?contentType=post
and when you click on each score's link, confirm that you get the same amount of posts with theamount
attribute of each post.For when the post type requested is excluded from indexable creation:
/wp-json/yoast/v1/seo_scores?contentType=page
Invalid content type
error.For when the term requested is not part of the taxonomy:
/wp-json/yoast/v1/seo_scores?contentType=post&taxonomy=category&term=<TERM_ID>
(replaceTERM_ID
with an ID that doesn't exist in terms)Invalid term
error.For a custom taxonomy that doesn't have links because it has a false
query_var
:query_var
attribute and assign it to books:/wp-json/yoast/v1/seo_scores?contentType=book&taxonomy=alternative-genre&term=<TERM_ID>
(replaceTERM_ID
with the correct term ID)Invalid taxonomy
erroralternative-genre
taxonomy as filter for books and repeat the GET request:1
):links
attributes - In those cases, we will have noView
buttons in the UI.Relevant test scenarios
Test instructions for QA when the code is in the RC
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Other environments
[shopify-seo]
, added test instructions for Shopify and attached theShopify
label to this PR.Documentation
Quality assurance
Innovation
innovation
label.Fixes https://github.com/Yoast/reserved-tasks/issues/321