Fix (sometimes serious) performance problem on submitting profiles for specified contacts #13606
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.
Overview
Prevents unnecessary soul-destroying & sometimes server-destroying queries when submitting a profile for a known contact id
Before
Despite the contact id being known ($form->_id) and ultimately used the code does expensive queries to retrieve possible duplicates (before discarding that information). When using a profile block with only tags in it with contactlayouteditor this creates a query that makes strong servers cry
After
Unnecessary queries not run
Technical Details
$form->_id is set when the contact id is known - e.g in edit, in contactlayouteditor profile
blocks. However, current logic still retrieves duplicates and then... does nothing
with them if ->_id is set. By moving the if up higher we can save the server from
doing unnecesary queries. Note that if you submit a tag profile with no other fields in it
the query is server-destroyingly bad with this
Comments
@colemanw here is the fix to civicrm/org.civicrm.contactlayout#46 following up on the preliminary refactor you reviewed.