Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP dev/core#748 Clean up transaction handling for CRM_Case_Form_Activity #13672

Closed

Conversation

mattwire
Copy link
Contributor

Overview

This is part of a task to solve performance issues/deadlocks caused by smartgroups/ACLs described here: https://lab.civicrm.org/dev/core/issues/748

Transactions should be automatically terminated when PHP execution completes, but the longer we are in a transaction the longer we are locking tables that may be needed by other processes.

Before

When performing create, edit, delete actions on case activities the database transaction is not explicitly committed/rolled back so tables are locked for longer than they need to be.

After

When performing create, edit, delete actions on case activities the database transaction is committed/rolled back as soon as it is no longer needed so tables are locked for the minimum amount of time.

Technical Details

Use $transaction->commit(), $transaction->rollback().

Comments

@seamuslee001 Would appreciate your thoughts on this if you have time?

There is also some unused variable/code cleanup in here.

@civibot
Copy link

civibot bot commented Feb 22, 2019

(Standard links)

@civibot civibot bot added the master label Feb 22, 2019
@mattwire
Copy link
Contributor Author

ping @pfigel @sluc23

@@ -372,7 +372,9 @@ public function postProcess($params = NULL) {
}
}
else {
$statusMsg = ts("Selected Activity cannot be deleted.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire so I feel like using the api would be more correct than doing rollback at the form layer.

It seems to me that activity.delete api should also delete entity tags within that action - so that bit of code should be moved into whatever activity.delete api calls (ideally with a test) & the form could call activity.delete rather than all this - which feels brittle

eileenmcnaughton pushed a commit to eileenmcnaughton/civicrm-core that referenced this pull request Feb 24, 2019
This is a reviewer's commit of civicrm#13672

I pulled out some lines I've checked & agree with to simplify that commit
@@ -440,15 +444,12 @@ public function postProcess($params = NULL) {

// build custom data getFields array
$customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields,
CRM_Utils_Array::crmArrayMerge($customFields,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from a cleanup pov - this line can completely go can't it?

@eileenmcnaughton
Copy link
Contributor

@mattwire I've pulled out a few lines to merge separately to reduce this PR to it's essence. My feeling is the form shouldn't be started a transaction at the start of postProcess - in general that doesn't feel like where transactions should be handled - I feel like if we refactor the 3? actions that might result from this form into their own functions then we could either start & end a transaction within each function or possibly use the api instead - esp the delete & restore ones feel like they should just be api calls whereas the bigger update fn might need a trxn wrapping for now unless we can move some stuff to the api

@mattwire mattwire changed the title dev/core#748 Clean up transaction handling for CRM_Case_Form_Activity WIP dev/core#748 Clean up transaction handling for CRM_Case_Form_Activity Feb 26, 2019
@mattwire mattwire force-pushed the transaction_caseformactivity branch from 5e54450 to f4b45c3 Compare February 26, 2019 10:41
@mattwire mattwire added the needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state label Apr 4, 2019
@mattwire
Copy link
Contributor Author

Closing pending review

@mattwire mattwire closed this Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants