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

PLANET-5870: Cache clear command #1286

Merged
merged 6 commits into from Feb 5, 2021
Merged

PLANET-5870: Cache clear command #1286

merged 6 commits into from Feb 5, 2021

Conversation

Inwerpsel
Copy link
Contributor

@Inwerpsel Inwerpsel commented Jan 27, 2021

Ref: https://jira.greenpeace.org/browse/PLANET-5870

Adding this as a command first so that we can make it a post-deploy step for test instances. We can start that way and observe if purging all html on each deployment causes any issues. Then we can set it up for a few production NROs and see how it goes. If it doesn't cause issues (e.g. Cloudflare deciding to evict us from cache more frequently once they pick up these entries usually don't live long), we could do this for all sites on each deploy.

I added a feature flag for this, so that we're not blocked to use it on production by needing more code changes. Tested off and on behavior on https://app.circleci.com/pipelines/github/greenpeace/planet4-test-janus/37/workflows/a3b88549-3fb8-4d73-926b-2e42e61b34ad/jobs/199

@Inwerpsel Inwerpsel force-pushed the cache-clear-command branch 3 times, most recently from 4365799 to af2e1dd Compare January 27, 2021 12:49
src/Commands.php Outdated Show resolved Hide resolved
@Inwerpsel Inwerpsel force-pushed the cache-clear-command branch 2 times, most recently from 940c267 to 6332e32 Compare January 27, 2021 18:26
* Option to purge all posts and per post type.
* Output link to test instance circleCI page
Copy link
Member

@lithrel lithrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check Sonar for code smell and complexity https://sonarcloud.io/project/issues?id=greenpeace_planet4-master-theme&pullRequest=1286&resolved=false&types=CODE_SMELL (not always fixable but interesting)

src/Commands.php Outdated
* Put the CF API key into the options table, where the CF plugin uses it from.
*/
$put_cf_key_in_db = static function ( $args ) {
$hostname = $args[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined offset if no args is given, ?? null would be nice :)

src/Commands.php Outdated

$domain_parts = explode( '.', $hostname );

$root_domain = implode( '.', array_slice( $domain_parts, - 2 ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we talk about this before ? 😬 I guess it's ok because we work mainly on greenpeace.org domain; I've used this lib https://github.com/jeremykendall/php-domain-parser in other projects, as it's impossible to guess the real root domain without a list of existing suffixes (domains in .co.uk woud fail here, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree it's a shaky way to get the root domain, but I only moved this code from Loader without changes, so I rather not blow up this PR by adding a new dependency 😅 We can look at it in a separate PR 👌

src/Commands.php Outdated
if ( ! defined( 'CLOUDFLARE_PLUGIN_DIR' ) ) {
define( 'CLOUDFLARE_PLUGIN_DIR', WP_PLUGIN_DIR . '/cloudflare/' );
}
require_once CLOUDFLARE_PLUGIN_DIR . 'vendor/autoload.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regular autoload doesn't work for this ? (it works locally without it at least)

Copy link
Contributor Author

@Inwerpsel Inwerpsel Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's really "autoloading" it, the classes happen to be loaded already at the point of execution. But if we don't add this then there's no explicit way of saying where these classes are coming from. If the plugin is not present this should also make it fail as early as possible.

src/Commands.php Outdated

if ( isset( $assoc_args['urls'] ) ) {
$urls = explode( ',', $assoc_args['urls'] );
} elseif ( $assoc_args['all'] ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isset() ?

@Inwerpsel
Copy link
Contributor Author

Inwerpsel commented Feb 4, 2021

Also check Sonar for code smell and complexity https://sonarcloud.io/project/issues?id=greenpeace_planet4-master-theme&pullRequest=1286&resolved=false&types=CODE_SMELL (not always fixable but interesting)

I followed Sonar and actually glad I did, it's much nicer to have each command in its own file. It's still tripping over a too long line and the runtime exception, but I don't think the latter is an issue for a command. Also Squiz doesn't understand @inheritDoc correctly, but seems they fixed it recently, maybe we can bump it instead of working around nevermind, no point delaying this for some phpdoc :) . squizlabs/PHP_CodeSniffer#2770 (comment)

@Inwerpsel Inwerpsel merged commit 5cfd476 into master Feb 5, 2021
@Inwerpsel Inwerpsel deleted the cache-clear-command branch February 5, 2021 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants