Make WordPress Core

Opened 8 weeks ago

Last modified 12 days ago

#47599 assigned defect (bug)

Return for short circuits for multisite classes.

Reported by: spacedmonkey Owned by: adamsilverstein
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.2
Component: Networks and Sites Keywords: has-patch needs-unit-tests
Focuses: multisite Cc:

Description (last modified by SergeyBiryukov)

In [44983] we introduced pre query filters in multisite classes. However this short circuit acts differently from other short circuits and still continues to execute. After the filter runs, it should exit straight away.

Attachments (4)

47599.diff (4.9 KB) - added by spacedmonkey 8 weeks ago.
from_ticket_47599_by_adamsilverstein__Pull_Request_76__WordPresswordpress-develop_2019-08-02_11-24-21.jpg (520.3 KB) - added by adamsilverstein 2 weeks ago.
47599.2.diff (6.5 KB) - added by adamsilverstein 12 days ago.
47599.3.diff (7.8 KB) - added by adamsilverstein 12 days ago.

Download all attachments as: .zip

Change History (11)

8 weeks ago

#1 @SergeyBiryukov
8 weeks ago

  • Description modified (diff)

#2 @SergeyBiryukov
8 weeks ago

  • Milestone changed from Awaiting Review to 5.3

#3 @adamsilverstein
4 weeks ago

@spacedmonkey Thanks for the patch!

Can you explain what problem this patch solves? are you still seeing database queries after returning an array of ids from this filter?

noticing that after this patch we loose handling in https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/class-wp-network-query.php#L247-L290 - including args like fields, count and update_network_cache.

Also the function get_networks usually returns an array of WP_Network objects - after this change it looks more like you the function would return an array of IDs, is that right?

#4 @adamsilverstein
2 weeks ago

Reviewing this diff without whitespace changes I can see the change here is smaller than what i thought and does exactly what our other filters do.

This looks good, thanks @spacedmonkey!


#5 @adamsilverstein
2 weeks ago

  • Keywords needs-unit-tests added

This could use a unit test to verify that these functions return early when the filters return non null values.

#6 @adamsilverstein
12 days ago

Question from @felipeelia related - https://core.trac.wordpress.org/ticket/45800#comment:21

Should we really be setting $this->sites here? before the filter depending on the query this could be set to ids, full objects or nothing (for a count request). Since we pass a reference to $this in the filter, maybe we should leave it up to filter consumers to set $this->sites?

In 47599.2.diff I updated our existing unit tests to account for requesting full objects not just ids. in this case previously additional database requests were made and the tests fail. after this patch the tests pass - no additional queries are run when a non null value is returned from the filter.

#7 @adamsilverstein
12 days ago

In 47599.3.diff:

  • improve documentation of filter, return type
  • don't set this->sites with return value

Diff without whitespace: https://github.com/WordPress/wordpress-develop/pull/78/files?w=1

Note: See TracTickets for help on using tickets.