Problem/Motivation

Currently, _block_rehash() writes to {block} far more often than it has to. Recently, we ran into issues caused by an excesses number of UPDATE {block} queries being run on cron run or a cache-clear. I traced this back to _block_rehash().

Proposed resolution

_block_rehash() begins by comparing what is in {block} to what is defined in modules' hook_block_info. By comparing the results of the {block} query to what is defined in hook_block_info before attempting to write to {block}, we can avoid a large number of the UPDATE {block} queries. A simple if wrapper around the drupal_write_record prevents the excess number of UPDATE {block} queries.

NOTE: _block_rehash() has been re-architected in D8 and this same issue is not present there.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ultimateboy’s picture

Status: Active » Needs review
FileSize
569 bytes
iamEAP’s picture

This is a way saner approach than what I had in mind here #1693336: Block rehashing happens on every cron run, which I've marked as a dupe.

#1 gets a +1 from me.

Status: Needs review » Needs work

The last submitted patch, block-rehash-if-2041107-1.patch, failed testing.

iamEAP’s picture

Status: Needs work » Needs review
FileSize
570 bytes

Just to rule this out...

Thought so. Array comparison in PHP can be tricky; I believe the double-equals checks type AND keys AND values AND order. This could result in db updates if (for whatever reason) a hook_block_info implementor changed the order of its keys, but that would be pretty edge-case; this should still drastically reduce the number of updates performed.

iamEAP’s picture

Status: Needs review » Needs work

Per a quick discussion on IRC, it would appear as though this actually doesn't have the desired effect.

Bumping back to "needs work."

ultimateboy’s picture

Status: Needs work » Closed (duplicate)

Marking as a duplicate of #1693336: Block rehashing happens on every cron run as it has a substantially better patch and roughly solves the same problem.