- πΊπΈUnited States TomTech
Automatically closed because Drupal 7 security and bugfix support has ended β as of 5 January 2025. If the issue verifiably applies β to later versions, please reopen with details and update the version.
In our experience, any queries that rely on a countQuery
(or in EFQ's case, count()
) on a large database table results in longer-than-expected query execution time. On production, the EFQ described by commerce_license_exists() actually took 1,080 ms (over 1 second) to check for some products on a user:
This issue is described on a few pages I've found where it is explained how COUNT queries on large InnoDB tables are expensive: 1, 2, and 3.
Our {commerce_license} table has 6.7 million rows, and increasing daily. This means we need to squeeze as much throughput as we can from expensive queries and functions such as this.
In addition, the function itself stores values in the static cache. However, if the statically cached result is 0
, the query is called again in all subsequent calls during the same request because of a check for empty()
, thereby negating the performance benefit of a static cache.
Remove the call to count()
and replace it with both a ranged query, and assign a boolean to the results array. Also, check for whether a result for this query !isset()
before performing the same query a second time for the same product_id.
Review and test.
None.
None. While the function itself was previously (in its current form) returning and storing the results of count()
, the function's comments note that the expected return value of commerce_license_exists()
is a Boolean.
None, unless modules are erroneously using the actual count value of returned results.
Closed: outdated
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Automatically closed because Drupal 7 security and bugfix support has ended β as of 5 January 2025. If the issue verifiably applies β to later versions, please reopen with details and update the version.