Invalidate cached ideas on server on idea activity
See original GitHub issueFeature Description
As mentioned on https://github.com/google/site-kit-wp/issues/3852, the logic for displaying a notice based on new or saved ideas can be based on stale cached ideas in transients. These are currently cached for 1 day and never manually invalidated, which can easily lead to the wrong notice shown or even a notice to show when none should be shown.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Transients for new and saved ideas should live no longer on the server side than on the client – their expiration times should be set to 1 hour
- Transients for new and saved ideas should be invalidated whenever actions are taken that would change the number of new or saved ideas (such as pinning, unpinning, or changes to post status)
Implementation Brief
In includes/Modules/Idea_Hub.php
:
- Everywhere (in
includes/Modules/Idea_Hub.php
) that we set our transients forDAY_IN_SECONDS
, change it toHOUR_IN_SECONDS
.
https://github.com/google/site-kit-wp/blob/63fc48c365cd98fad1d0706d0c7835d03696565a/includes/Modules/Idea_Hub.php#L306 https://github.com/google/site-kit-wp/blob/63fc48c365cd98fad1d0706d0c7835d03696565a/includes/Modules/Idea_Hub.php#L343 https://github.com/google/site-kit-wp/blob/63fc48c365cd98fad1d0706d0c7835d03696565a/includes/Modules/Idea_Hub.php#L356
We delete transients with $this->transients->delete()
Idea pinning and deleting is via the endpoint update-idea-state
, so we update it to delete the two transients TRANSIENT_SAVED_IDEAS
and TRANSIENT_NEW_IDEAS
prior to the return statement in the parse_data_response
function:
https://github.com/google/site-kit-wp/blob/63fc48c365cd98fad1d0706d0c7835d03696565a/includes/Modules/Idea_Hub.php#L635
Idea creation is via the endpoint create-idea-draft-post
, so we update it to delete the two transients TRANSIENT_SAVED_IDEAS
and TRANSIENT_NEW_IDEAS
prior to the return statement:
https://github.com/google/site-kit-wp/blob/63fc48c365cd98fad1d0706d0c7835d03696565a/includes/Modules/Idea_Hub.php#L513
Test Coverage
- N/A
Visual Regression Changes
QA Brief
- See https://github.com/google/site-kit-wp/issues/3852: we should now see the notices change correctly on the WP Posts page when ideas are pinned and unpinned.
Changelog entry
- Update the
Idea_Hub
class to invalidate cached ideas when an idea is modified or a new post is created.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
@aaemnnosttv but that’s already covered in the IB by the
create-idea-draft-post
endpoint update.QA Update: ✅
Verified:
Want some inspiration for a new post? Revisit your saved ideas in Site Kit
Want some inspiration for a new post? Review your new ideas in Site Kit