[wp-trac] [WordPress Trac] #39428: Die fast in get_posts if get_user_by returns false

WordPress Trac noreply at wordpress.org
Sun Jun 15 10:55:15 UTC 2025


#39428: Die fast in get_posts if get_user_by returns false
-------------------------------------------------+-------------------------
 Reporter:  david.binda                          |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Query                                |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch changes-requested has-     |     Focuses:
  unit-tests                                     |  performance
-------------------------------------------------+-------------------------
Changes (by SirLouen):

 * keywords:  has-patch has-unit-tests needs-testing => has-patch changes-
     requested has-unit-tests
 * focuses:   => performance


Comment:

 Replying to [ticket:39428 david.binda]:
 > 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.

 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 two `assertNotRegExp` and good
 to go.

 I've added
 [https://core.trac.wordpress.org/attachment/ticket/39428/39428.2.diff 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/39428#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list