Problem/Motivation

On initial order creation/save, there is a hook_ENTITY_insert to update the order number. This poorly performs on a site that is taking lots of order in short order, pun intended.

Proposed resolution

Add the order_number at entity load time, it will then get written to the DB on next save.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

heddn created an issue. See original summary.

heddn’s picture

Status: Active » Needs review
FileSize
1.64 KB
khiminrm’s picture

I’ve checked the patch. By using those patch, revision table do not have initial value of order_number, views show empty value for new created order_number. Also commerce_order_load_by_number() doesn’t work for new created orders.

khiminrm’s picture

Re-rolled patch to current dev version

rszrama’s picture

Status: Needs review » Needs work

@khiminrm So this needs to go back to needs work I guess?

rszrama’s picture

Status: Needs work » Fixed

I'm going to won't fix this, as I don't see a feasible path forward after trying to make it work in a project w/ khiminrm. The biggest problem I see is that you don't actually know when the next save for the order will occur. This could leave you without an order number for quite some time, and it would certainly throw off the sequential ordering of numbers even worse than already occurs.

My recommendation would be to set the order number in a pre-save hook if this were an issue on a given client site. I think the actual implementation will need to vary per the site's specific needs.

rszrama’s picture

Category: Task » Support request

Sorry, just converting this to a support request so all involved still receive credits for their research. Thanks, @all!

Status: Fixed » Closed (fixed)

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