In the typical creation of an order, we do:

  • Create and save an empty order, to get an order_id
  • Create and save the line items
  • Attach the line items to the order
  • Save the order

During the save process, the order total gets computed, and we load from the database, even if we just saved them. I suggest that we should store the saved entity in the cache instead of simply clearing it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Issue tags: +Performance

Tagging.

Damien Tournoud’s picture

Status: Active » Needs review
FileSize
906 bytes

Status: Needs review » Needs work
Issue tags: -Performance

The last submitted patch, 1363814-entity-controller-store-saved-static-cache.patch, failed testing.

bojanz’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Performance

The last submitted patch, 1363814-entity-controller-store-saved-static-cache.patch, failed testing.

bojanz’s picture

FileSize
2.64 KB

So, this goes against the pessimistic locking, since entityCache never gets emptied, the transaction never gets committed, and bad stuff happens.

There are two ways to solve this:
1) Only doing the performance optimization if pessimistic locking is disabled.
This is okay for our use case (where pessimistic locking might be disabled anyway), but it's still less than ideal.

2) The attached patch.
The problem with this patch is that it does exactly what we needed it to do.
Which means this:
a. You load an order. It gets locked.
b. You save an order. It gets unlocked but stays in entity cache.
c. You load an order again. It is now in an unlocked state, since it was fetched from entity cache.
This means that the pessimistic locking is no longer guaranteed.

Leaving the final call to Damien.

Damien Tournoud’s picture

Status: Needs work » Needs review

Let's see if this fixes the testing issue.

Status: Needs review » Needs work

The last submitted patch, locking.patch, failed testing.

Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
3.01 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 1363814-entity-controller-store-saved-static-cache.patch, failed testing.

bojanz’s picture

Still fails, it seems.

amateescu’s picture

Status: Needs work » Needs review
FileSize
6.08 KB
7.67 KB

@bojanz forgot to empty the lockedEntities array if no arguments were passed to resetCache(). This should fix the tests :)

New patch and interdiff from #9.

Damien Tournoud’s picture

Status: Needs review » Reviewed & tested by the community

Woo. Great catch, @amateescu!

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Committed with some minor whitespace changes. I don't see any direct answer to Bojan's question in #6 above with respect to orders "loaded" after a save being unlocked since they came from the cache. Based on Damien's RTBC, I assume this isn't a concern to him.

Thanks again to everyone for the group effort. Tests passed locally, too.

Damien Tournoud’s picture

@rszrama: this patch doesn't change the behavior in this regard. We should deal with the remaining locking issues in a separate issue.

Automatically closed -- issue fixed for 2 weeks with no activity.