Problem/Motivation

The query to the block table in context_reaction_block::get_blocks() retrieves all fields from the table, even though it doesn't use all of the data it retrieves. On sites with a large number of blocks, this causes unnecessary performance impact.

Proposed resolution

Limit the query to only ask for the fields it needs and cache the results.

Remaining tasks

  • Needs tests.
  • This patch introduces a new cache key but does not flush that cache. Presumably the cache needs to be flushed when block data change.

User interface changes

API changes

Data model changes

Comments

jrbeeman’s picture

Status: Active » Closed (won't fix)

Sorry - realized this is inaccurate.

mikeytown2’s picture

Title: Improve performance of query in context_reaction_block::get_blocks() » Cache query in context_reaction_block::get_blocks() & remove unused blocks before the alters get called.
Status: Closed (won't fix) » Needs review
StatusFileSize
new3.17 KB

If using panels_mini, this can save around 10ms per block removed. Also caching the query helps by another 20ms.

Patch also fixes some minor white space issues.

mikeytown2’s picture

Assigned: jrbeeman » Unassigned
mikeytown2’s picture

mikeytown2’s picture

mikeytown2’s picture

sgdev’s picture

Any movement on this patch? We've been using it successfully on a site for a while.

I'd mark as RTBC, but would be good to have others give their feedback.

mikeytown2’s picture

Well you know I've been using it as well. There's not a lot of followers on this issue so go ahead and make it RTBC.

sgdev’s picture

Status: Needs review » Reviewed & tested by the community

Done, thanks...

hass’s picture

Can you add tests for this?

Aside, why is the result cached unaltered? I'm not sure if this is best practice...

mikeytown2’s picture

why is the result cached unaltered

My reasoning was that the alter might do something based off of some external context (like user, url, theme, etc). Currently doing a search in Gotta Download Them All via grep -rn -e "_context_block_info_alter(" ./ to see if I can find any use cases where this is true.

Looking over it and the hook gets implemented in 3 places; most complex is inside of the i18n_block module.
defaultcontent.module - defaultcontent_context_block_info_alter(&$blocks)
i18n_block.module - i18n_block_context_block_info_alter(&$block_info)
blocks_mass_cache.module - blocks_mass_cache_context_block_info_alter(&$blocks)

I'm not 100% sure caching the alter would be safe due the the usage of theme_default; see http://drupal.stackexchange.com/questions/161300/page-caching-wrong-css for an example of this being dynamic.

mikeytown2’s picture

Opps wrong hook
http://cgit.drupalcode.org/context/tree/plugins/context_reaction_block.i...

Looking at these 2

        drupal_alter('block_list', $result);
        drupal_alter('context_block_list', $result);

Nothing implements hook_context_block_list_alter but there's a lot of modules that implement hook_block_list_alter. This alter can not be cached.

Also noted that the theme is appart of the cid for this cache so the previous alter would have been ok; issue is hook_block_list_alter is used everywhere, pulling in external context that we can never know about, thus making it uncacheable.

mikeytown2’s picture

So a test case would be to make sure that hook_context_block_list_alter only gets blocks for the given region and not all of the blocks. Is there any coverage for get_blocks currently?

hass’s picture

No idea. I'm new to this module and just fixed a bunch of menu issues. I'd only like to prevent failures in future.

glynster’s picture

+ RTBC makes a big difference for us.

nedjo’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
  • Needs tests.
  • This patch introduces a new cache key but does not flush that cache. Presumably the cache needs to be flushed when block data change.

Setting to needs work.