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

Incorrect use of $query->get_posts(), resulting in double request processing #7781

Open
OlaIola opened this issue Apr 29, 2024 · 4 comments · May be fixed by #7782
Open

Incorrect use of $query->get_posts(), resulting in double request processing #7781

OlaIola opened this issue Apr 29, 2024 · 4 comments · May be fixed by #7782
Labels
Bug Something isn't working Performance
Projects
Milestone

Comments

@OlaIola
Copy link

OlaIola commented Apr 29, 2024

Bug Description

The WP_Query() constructor calls $this->get_posts() inside __constructor() and it is the longest method in the class and the next time it is called it does not return the result but rebuilds the entire query. The plugin uses this methog in 5 places.

Expected Behaviour

The same as before but avoiding unnecessary data processing and requests.

Screenshots

No response

PHP Version

No response

Plugin Version

2.5.3

AMP plugin template mode

Standard

WordPress Version

6.5

Site Health

No response

Gutenberg Version

No response

OS(s) Affected

No response

Browser(s) Affected

No response

Device(s) Affected

No response

Acceptance Criteria

No response

Implementation Brief

No response

QA Testing Instructions

No response

Demo

No response

Changelog Entry

No response

@OlaIola OlaIola added the Bug Something isn't working label Apr 29, 2024
@westonruter
Copy link
Member

@OlaIola Hi! So you're saying that anywhere that we're calling $query->get_posts() we should replace with $query->posts?

@OlaIola
Copy link
Author

OlaIola commented Apr 30, 2024

Hi @westonruter 👋🏻
We should use getters if possible, but in this case it is not working as expected, and $posts property is public, so $query->posts is fine and will be a minimal change. Or it can be:

$query = new WP_Query(); 
$found_posts = $query->query( $args );

@westonruter westonruter added this to the v2.5.4 milestone Apr 30, 2024
@westonruter westonruter linked a pull request Apr 30, 2024 that will close this issue
2 tasks
@westonruter westonruter added this to Backlog in Ongoing via automation Apr 30, 2024
@westonruter westonruter moved this from Backlog to Ready for Review in Ongoing Apr 30, 2024
@westonruter
Copy link
Member

I've opened #7782 to fix this.

@OlaIola How did you discover this issue?

@OlaIola
Copy link
Author

OlaIola commented Apr 30, 2024

I discovered this issue at my own code with Query Monitor, it indicated that I am making some requests twice. Data can be served from the cache object the second time, but WP_Query is still processing the request. Query Monitor is not working with feeds, but I went to look in the site code base for this issue in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Performance
Projects
Ongoing
  
Ready for Review
Development

Successfully merging a pull request may close this issue.

2 participants