Opened 9 years ago
Last modified 9 months ago
#39428 new defect (bug)
Die fast in get_posts if get_user_by returns false
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 4.7 |
| Component: | Query | Keywords: | has-patch changes-requested has-unit-tests |
| Focuses: | performance | Cc: |
Description
In case a username in the URL or passed to WP_Query via any other way is invalid - such a user is not in database - the code currently casts the false value returned from get_user_by to 0 via absint - see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-query.php#L2126
Instead of trying to query unassigned posts (with post_author equal to 0) for all invalid usernames, the query should die fast and return no posts.
Attachments (2)
Change History (5)
Note: See
TracTickets for help on using
tickets.
Replying to david.binda:
Why not short-circuiting fast and furiously?
Unit tests are too focused on that strange SQL condition of
1==0. I think can be simpler, just ignoring those twoassertNotRegExpand good to go.I've added a patch with this.
If you like, you can integrate changes in a GitHub PR (both short-circuit and changes in Unit-Tests), and we could try to move this forward. It's a very niche case, but it's true that we save at least, one query to the DB. It's a little performance gain.