Use an Index on the 'code' field in commerce_wishlist table

Created on 27 June 2024, 6 months ago
Updated 2 July 2024, 6 months ago

Problem/Motivation

NewRelic was reporting a spike of slow queries all relating to adding an item to a wishlist. The stack trace shows a lot of entity loads/saves etc etc but what stood out was the use of the wishlist code field to pluck data out of the DB.

I noticed, that the code column isn't indexed. Out of the box, there are 6 indexes on the commerce_wishlist table, code not being included in one of them. After adding an index in for code we noticed the performance of our wishlist queries increase by 3 orders of magnitude.
So for a simple select query that WishlistStorage::loadByCode($code) performs, we saw query speeds of 441ms and after popping an index in, we got that time down to 0.1ms. A significant increase in speed!

Proposed resolution

Define a storage schema handler that defines an index on the code base field.

Add an update hook that informs Drupal of the new handler, which adds the new index.

Feature request
Status

Needs review

Component

Code

Created by

🇬🇧United Kingdom ChristianSanders

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024