Repository navigation
Listings: search several locations with one postmeta JOIN - #3189
Open
benitoalba wants to merge 1 commit into
Open
benitoalba wants to merge 1 commit into
benitoalba wants to merge 1 commit into
Conversation
A location search such as "Chicago; Boston; Seattle" built one nested OR group per location. WP_Meta_Query gives each nested group its own wp_postmeta JOIN, joined on post_id only, so every extra location multiplied the rows examined by the number of meta rows on a listing. Put all clauses in a single OR group, which WP_Meta_Query serves from one JOIN. The condition is logically the same, so results don't change. The shared helper job_manager_get_location_meta_query() replaces the copies in get_job_listings() and the job feed. Fixes Automattic#3178.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3178
Changes Proposed in this Pull Request
Chicago; Boston; Seattlebuilt one nestedORgroup per location.WP_Meta_Querygives each nested group its ownwp_postmetaJOIN, and those JOINs are onpost_idonly, so every extra location multiplies the rows examined by the number of meta rows on a listing. With about 25 meta rows per listing that is roughly ×25 per location, which matches the timings in the issue.ORgroup.WP_Meta_Queryshares one JOIN between siblingLIKEclauses in anORgroup, so the query has one postmeta JOIN however many locations are searched.(A1 OR A2 OR A3) OR (B1 OR B2 OR B3)is the same condition as the flat list.get_job_listings()andWP_Job_Manager_Post_Types::job_feed(). Both now call a new helper,job_manager_get_location_meta_query(). (The issue mentions the admin list filter; the second copy I found in trunk is the job feed.)Timings on a local site with 170 listings, 25 meta rows each, MariaDB 12.3, result cache off:
The returned listing IDs were identical on trunk and this branch for 1, 2 and 3 locations. For 4 locations I compared the count only (86 on both), because trunk takes 41 s per run.
Note that #3039 and #3021 touch the same loop, so whichever lands second will need a small rebase.
Testing Instructions
[jobs]page, search the location field for one city, e.g.Chicago, and note the results.Chicago; Boston; Seattle; London. On trunk this takes many seconds or times out; on this branch it returns straight away with the listings from all four cities./?feed=job_feed&search_location=Chicago;Boston;Seattle;London, and check it returns the same listings quickly.make test(new tests:--filter 'multiple_location|location_meta_query').Release Notes
New or Updated Hooks and Templates
job_manager_get_location_meta_query( $search_location ): returns the meta query group used to match listings in any of the semicolon-separated locations. I tagged it@since 2.4.13; happy to change that to whatever the next version is.