Skip to content
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

[BUGS-5990] Prefix surrogate keys with blog ID on WPMS #228

Merged
merged 16 commits into from
Apr 18, 2023
37 changes: 27 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,34 @@ Pull requests and issues are welcome!

## Workflow

The `develop` branch is the development branch which means it contains the next version to be released. `master` contains the corresponding stable development version. Always work on the `develop` branch and open up PRs against `develop`.
Development and releases are structured around two branches, `develop` and `master`. The `develop` branch is the default branch for the repository, and is the source and destination for feature branches.

We prefer to squash commits (i.e. avoid merge PRs) from a feature branch into `develop` when merging, and to include the PR # in the commit message. PRs to `develop` should also include any relevent updates to the changelog in readme.txt. For example, if a feature constitutes a minor or major version bump, that version update should be discussed and made as part of approving and merging the feature into `develop`.

`develop` should be stable and usable, though possibly a few commits ahead of the public release on wp.org.

The `master` branch matches the latest stable release deployed to [wp.org](wp.org).

## Release Process

1. Starting from `develop`, cut a release branch named `release_X.Y.Z` containing your changes.
1. Update plugin version in `package.json`, `README.md`, `readme.txt`, and `pantheon-advanced-page-cache.php`.
1. Update the Changelog with the latest changes.
1. Create a PR against the `master` branch.
1. After all tests pass and you have received approval from a CODEOWNER (including resolving any merge conflicts), merge the PR into `master`.
1. Pull `master` locally, create a new tag, and push up.
1. From `develop`, checkout a new branch `release_X.Y.Z`.
1. Make a release commit:
* Drop the `-dev` from the version number in `package.json`, `README.md`, `readme.txt`, and `pantheon-advanced-page-cache.php`.
* Update the "Latest" heading in the changelog to the new version number with the date
* Commit these changes with the message `Release X.Y.Z`
* Push the release branch up.
1. Open a Pull Request to merge `release_X.Y.Z` into `main`. Your PR should consist of all commits to `develop` since the last release, and one commit to update the version number. The PR name should also be `Release X.Y.Z`.
1. After all tests pass and you have received approval from a [CODEOWNER](./CODEOWNERS), merge the PR into `main`. "Rebase and merge" is preferred in this case. _Never_ squash to `main`.
1. Pull `master` locally, create a new tag (based on version number from previous steps), and push up. The tag should _only_ be the version number. It _should not_ be prefixed `v` (i.e. `X.Y.Z`, not `vX.Y.X`).
1. Confirm that the necessary assets are present in the newly created tag, and test on a WP install if desired.
1. Create a [new release](https://github.com/pantheon-systems/pantheon-advanced-page-cache/releases/new) using the tag created in the previous steps, naming the release with the new version number, and targeting the tag created in the previous step. Paste the release changelog from the `Changelog` section of the `README` into the body of the release and include a link to the closed issues if applicable.
1. Wait for the [_Release pantheon-advanced-page-cache plugin to wp.org_ action](https://github.com/pantheon-systems/pantheon-advanced-page-cache/actions/workflows/wordpress-plugin-deploy.yml) to finish deploying to the WordPress.org repository. If all goes well, users with SVN commit access for that plugin will receive an emailed diff of changes.
1. Check WordPress.org: Ensure that the changes are live on https://wordpress.org/plugins/pantheon-advanced-page-cache/. This may take a few minutes.
1. Create a [new release](https://github.com/pantheon-systems/pantheon-advanced-page-cache/releases/new) using the tag created in the previous steps, naming the release with the new version number, and targeting the tag created in the previous step. Paste the release changelog from the `Changelog` section of [the readme](readme.txt) into the body of the release, including the links to the closed issues if applicable.
1. Wait for the [_Release pantheon-advanced-page-cache plugin to wp.org_ action](https://github.com/pantheon-systems/pantheon-advanced-page-cache/actions/workflows/wordpress-plugin-deploy.yml) to finish deploying to the WordPress.org plugin repository. If all goes well, users with SVN commit access for that plugin will receive an emailed diff of changes.
1. Check WordPress.org: Ensure that the changes are live on [the plugin repository](https://wordpress.org/plugins/pantheon-advanced-page-cache/). This may take a few minutes.
1. Following the release, prepare the next dev version with the following steps:
* `git checkout develop`
* `git rebase master`
* Update the version number in all locations, incrementing the version by one patch version, and add the `-dev` flag (e.g. after releasing `1.2.3`, the new verison will be `1.2.4-dev`)
* Add a new `** Latest **` heading to the changelog
* `git add -A .`
* `git commit -m "Prepare X.Y.X-dev"`
* `git push origin develop`
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Tags:** pantheon, cdn, cache
**Requires at least:** 4.7
**Tested up to:** 6.2
**Stable tag:** 1.2.4
**Stable tag:** 1.3.0-dev
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -308,22 +308,25 @@ See [CONTRIBUTING.md](https://github.com/pantheon-systems/pantheon-advanced-page

## Changelog ##

## 1.2.4 (April 13, 2023) ##
* Adds surrogate key to post-type archive pages (eg, "portfolio") that's specific to that archive( eg "portfolio-archive"), and clears that archive where appropriate. [[#225](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/225)]
### Latest ###
* Adds support for WordPress Multisite which resolves issue where editing a Post on one subsite clears the home page cache of other sites in the Multisite install if it has a Post containing the same ID [[#228](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/228)].

## 1.2.3 (April 5, 2023) ##
### 1.2.4 (April 13, 2023) ###
* Adds surrogate key to post-type archive pages (e.g. "portfolio") that's specific to that archive(e.g. "portfolio-archive"), and clears that archive where appropriate [[#225](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/225)].

### 1.2.3 (April 5, 2023) ###
* Bump tested up to version to 6.2

## 1.2.2 (March 14, 2023) ##
### 1.2.2 (March 14, 2023) ###
* Adds PHP 8.2 compatibility [[#218](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/218)].
* Bump dependencies [[#204](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/204)].

## 1.2.1 (February 23, 2023) ##
### 1.2.1 (February 23, 2023) ###
* Handle models that are not instances of the `WPGraphQL\Model\Model` class [[#212](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/212)].
* Make dependabot target develop branch [[#209](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/209)].
* Bump dependencies [[#210](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/210)] [[#214](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/214)].

## 1.2.0 (November 29, 2022) ##
### 1.2.0 (November 29, 2022) ###
* Adds Github Actions for building tag and deploying to wp.org. Add CONTRIBUTING.md. [[#203](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/203)]

### 1.1.0 (November 1, 2022) ###
Expand Down Expand Up @@ -365,3 +368,8 @@ See [CONTRIBUTING.md](https://github.com/pantheon-systems/pantheon-advanced-page

### 0.1.0 (November 23rd, 2016) ###
* Initial release.

## Upgrade Notice ##

### Latest ###
Note that the Pantheon Advanced Page Cache Latest release now prefixes keys on a WordPress Multisite (WPMS) with the blog ID. For users who already have this plugin installed on a WPMS, they will need to click the Clear Cache button on the settings page to generate the prefixed keys.
6 changes: 3 additions & 3 deletions inc/class-emitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static function get_main_query_surrogate_keys() {
*
* @param array $keys Existing surrogate keys generated by the plugin.
*/
$keys = array_unique( $keys );
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
$keys = apply_filters( 'pantheon_wp_main_query_surrogate_keys', $keys );
$keys = array_unique( $keys );
$keys = self::filter_huge_surrogate_keys_list( $keys );
Expand All @@ -312,7 +312,7 @@ public static function get_rest_api_surrogate_keys() {
* @param array $keys Existing surrogate keys generated by the plugin.
*/
$keys = self::get_instance()->rest_api_surrogate_keys;
$keys = array_unique( $keys );
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
$keys = apply_filters( 'pantheon_wp_rest_api_surrogate_keys', $keys );
$keys = array_unique( $keys );
$keys = self::filter_huge_surrogate_keys_list( $keys );
Expand Down Expand Up @@ -416,7 +416,7 @@ public static function get_graphql_surrogate_keys() {
*/
$keys = self::get_instance()->graphql_surrogate_keys;
$keys[] = 'graphql-collection';
$keys = array_unique( $keys );
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
$keys = apply_filters( 'pantheon_wp_graphql_surrogate_keys', $keys );
$keys = array_unique( $keys );
$keys = self::filter_huge_surrogate_keys_list( $keys );
Expand Down
10 changes: 10 additions & 0 deletions inc/class-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static function action_clean_post_cache( $post_id ) {
'post-huge',
'rest-post-huge',
];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when clearing post cache.
*
Expand All @@ -95,6 +96,7 @@ public static function action_clean_post_cache( $post_id ) {
public static function action_created_term( $term_id, $tt_id, $taxonomy ) {
self::purge_term( $term_id );
$keys = [ 'rest-' . $taxonomy . '-collection' ];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when creating a new term.
*
Expand Down Expand Up @@ -139,6 +141,7 @@ public static function action_clean_term_cache( $term_ids ) {
}
$keys[] = 'term-huge';
$keys[] = 'rest-term-huge';
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when clearing term cache.
*
Expand All @@ -164,6 +167,7 @@ public static function action_wp_insert_comment( $id, $comment ) {
'rest-comment-collection',
'rest-comment-huge',
];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when inserting a new comment.
*
Expand All @@ -188,6 +192,7 @@ public static function action_transition_comment_status( $new_status, $old_statu
'rest-comment-collection',
'rest-comment-huge',
];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when transitioning a comment status.
*
Expand All @@ -210,6 +215,7 @@ public static function action_clean_comment_cache( $comment_id ) {
'rest-comment-' . $comment_id,
'rest-comment-huge',
];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when cleaning comment cache.
*
Expand Down Expand Up @@ -261,6 +267,7 @@ private static function purge_post_with_related( $post ) {
$keys[] = 'term-huge';
}
}
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Related surrogate keys purged when purging a post.
*
Expand All @@ -285,6 +292,7 @@ private static function purge_term( $term_id ) {
'rest-term-huge',
'post-term-huge',
];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when purging a term.
*
Expand All @@ -308,6 +316,7 @@ public static function action_clean_user_cache( $user_id ) {
'user-huge',
'rest-user-huge',
];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when clearing user cache.
*
Expand Down Expand Up @@ -336,6 +345,7 @@ public static function action_updated_option( $option ) {
'rest-setting-' . $rest_name,
'rest-setting-huge',
];
$keys = pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys );
/**
* Surrogate keys purged when updating an option cache.
*
Expand Down
25 changes: 24 additions & 1 deletion pantheon-advanced-page-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://pantheon.io
* Text Domain: pantheon-advanced-page-cache
* Domain Path: /languages
* Version: 1.2.4
* Version: 1.3.0-dev
*
* @package Pantheon_Advanced_Page_Cache
*/
Expand Down Expand Up @@ -77,6 +77,29 @@ function pantheon_wp_clear_edge_all() {
return true;
}

/**
* Prefix surrogate keys with the blog ID to provide compatibility with WPMS. See https://github.com/pantheon-systems/pantheon-advanced-page-cache/issues/196.
*
* @param array $keys Keys to be prefixed.
*/
function pantheon_wp_prefix_surrogate_keys_with_blog_id( $keys ) {
// Do not prefix keys if this is not a multisite install.
if ( ! is_multisite() ) {
return $keys;
}

// Array that will hold the new keys.
$prefixed_keys = [];

$prefix = 'blog-' . get_current_blog_id() . '-';
$prefix = apply_filters( 'pantheon_wp_surrogate_key_prepend', $prefix );
foreach ( $keys as $key ) {
$prefixed_keys[] = $prefix . $key;
}

return $prefixed_keys;
}

/**
* Registers the class autoloader.
*/
Expand Down
Loading