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

:closes: Fix issue with warm up link for homepage #6742

Merged
merged 13 commits into from
Jul 1, 2024

Conversation

Khadreal
Copy link
Contributor

Description

Fixes #6697

Documentation

User documentation

Explain how this code impacts users.

Technical documentation

Explain how this code works. Diagram & drawings are welcomed.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

New dependencies

List any new dependencies that are required for this change.

Risks

List possible performance & security issues or risks, and explain how they have been mitigated.

Checklists

Feature validation

  • I validated all the Acceptance Criteria. If possible, provide sreenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote self-explanatory code about what it does.
  • I wrote comments to explain why it does it.
  • I named variables and functions explicitely.
  • I protected entry points against unexpected inputs.
  • I did not introduce unecessary complexity.
  • I listed the introduced external dependencies explicitely on the PR.
  • I validated the repo-specific guidelines from CONTRIBUTING.md.

Observability

  • I handled errors when needed.
  •  I wrote user-facing messages that are understandable and provide actionable feedbacks.
  • I prepared ways to observe the implemented system (logs, data, etc.).

Risks

  •  I explicitely mentioned performance risks in the PR.
  • I explicitely mentioned security risks in the PR.

Copy link

codacy-production bot commented Jun 26, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for a8da7ae1 100.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a8da7ae) Report Missing Report Missing Report Missing
Head commit (918f3c0) 37293 14485 38.84%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6742) 3 3 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences


🚀 Don’t miss a bit, follow what’s new on Codacy.

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

Copy link
Contributor

@MathieuLamiot MathieuLamiot left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! It helped me understanding the issue and the approach.
While this PR should solve the issue, may I suggest a different approach? Reading this PR gave me an idea, and I think it could be good to discuss it to have a "cleaner" fix I think.

Actually, the root cause of the issue is that, on fresh install, the warm_up_home is called before the options cache_mobile and do_caching_mobile_files are set! This is due to the fact that warm_up_home is triggered with the register_activation_hook (activate_plugin -> rocket_after_activation) while options are set on admin_init which occurs after.
To confirm this, I added the following logs:

function rocket_upgrader() {
	// Grab some infos.
	
	$actual_version = (string) get_rocket_option( 'version', '' );
	// You can hook the upgrader to trigger any action when WP Rocket is upgraded.
	// first install.
	if ( ! $actual_version ) {
		error_log(" MLT TEST - FIRST INSTALL");
		do_action( 'wp_rocket_first_install' );
	}

To spot when the options are set (in wp_rocket_first_install)

And

	private function is_mobile( bool $is_warm_up = false ): bool {
		error_log(" MLT TEST - " . (string) get_rocket_option( 'version', '' ));
		error_log(" MLT TEST - " . (string) $this->options->get( 'cache_mobile', 'not here' ));
		error_log(" MLT TEST - " . (string) $this->options->get( 'do_caching_mobile_files', 'not here' ));
		if ( $is_warm_up ) {
			return true;
		}

		return $this->options->get( 'cache_mobile', 0 ) && $this->options->get( 'do_caching_mobile_files', 0 );
	}

Here is the output upon fresh install:

[26-Jun-2024 17:59:37 UTC]  MLT TEST - 
[26-Jun-2024 17:59:37 UTC]  MLT TEST - not here
[26-Jun-2024 17:59:37 UTC]  MLT TEST - not here
[26-Jun-2024 17:59:38 UTC]  MLT TEST - FIRST INSTALL

This confirms the order of execution of the actions, hence the issue.

To solve the issue, ie. send desktop + mobile homepage on fresh install, and keep the existin behavior the rest of the time, I would suggest the following rewrite of inc/Engine/Media/AboveTheFold/WarmUp/Controller.php -> is_mobile

	/**
	 * Check if separate cache for mobile is configured.
	 *
	 * @return bool
	 */
	private function is_mobile(): bool {
		$plugin_version = (string) get_rocket_option( 'version', '' );
		if ( ! $plugin_version ) { # We are warming up a fresh install. Options are not set yet.
			return true;
		}

		return $this->options->get( 'cache_mobile', 0 ) && $this->options->get( 'do_caching_mobile_files', 0 );
	}

inc/Engine/Media/AboveTheFold/WarmUp/Controller.php Outdated Show resolved Hide resolved
inc/Engine/Media/AboveTheFold/WarmUp/Controller.php Outdated Show resolved Hide resolved
inc/Engine/Media/AboveTheFold/WarmUp/Controller.php Outdated Show resolved Hide resolved
@Mai-Saad
Copy link
Contributor

@MathieuLamiot
Copy link
Contributor

@wp-media/qa-team The PR won't completely fix the issue, just improve it a bit (should warm up homepage sometimes on fresh installs, but not consistently). But we still expect that homepage might not be warmed_up systematically on fresh installs: the requests to the SaaS will be made and visible on Metabase, but the beacon might not be injected. (it's flaky, so not always reproducible, there is a race condition).
The real fix will be complex so we opened a dedicated issue : #6746

I would say maybe we can make this a NoQA since there is no consistent change in behavior? NRT would be enough to ensure there are no warning/Errors (the code change is quite small, that should be quick). WDYT?

@Khadreal Khadreal marked this pull request as ready for review June 28, 2024 13:13
@Khadreal Khadreal requested review from a team and MathieuLamiot June 28, 2024 13:14
@MathieuLamiot
Copy link
Contributor

I completed the test plan: https://wpmediaqa.testrail.io/index.php?/runs/view/864&group_by=cases:section_id&group_order=asc

Two issues:
For one of the fresh install, the homepage was missing. Due to #6746 I think. It happened once, and I could not reproduce systematically.
I was not able to perform the test on nest.rocketlabsqa as I can't find credentials.

@Mai-Saad
Copy link
Contributor

Mai-Saad commented Jul 1, 2024

The PR generally enhances the warmup with the following notes which will be handled on separate issues

@Mai-Saad Mai-Saad added this pull request to the merge queue Jul 1, 2024
Merged via the queue into develop with commit cb820e9 Jul 1, 2024
13 checks passed
@Mai-Saad Mai-Saad deleted the warmup-fetch-link#6697 branch July 1, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warmup fetch links - Mobile version missing from DB (ATF table) for Homepage URL on fresh installs
3 participants