hook_flush_caches gets unintentionally invoked on system_cron() as well as drupal_flush_all_caches(). As a result, it regenerates breakpoints and kills menu and theme caches for all themes enabled every single time.

This is a major issue for sites that have cron running every minute and even if you use cron managers, this still gets invoked because it's called in system_cron function.

While breakpoint regeneration is needed and should be regenerated on actual cache clean, this also gets invoked on settings form submit and on system_cron.

For breakpoints to be regenerated, this module has implemented hook_flush_caches, but it collides with this part of system_cron function.

$core = array('cache', 'cache_path', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
  $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
  foreach ($cache_tables as $table) {
    cache_clear_all(NULL, $table);
  }

The only way to distinguish where it is invoked, we are must trace code execution and run this code only when it's run trough drupal_flush_all_caches function (this function is called by both UI cache clean and drush cc all, so it's safe). This approach is also used by memcache module for slightly different purpose and is related to issue http://drupal.org/node/81461

Stack trace for breakpoints_flush_caches:
$trace[3] drupal_flush_all_caches
$trace[3] system_cron

This is proposed solution for breakpoints_flush_caches function, will attach patch shortly:

$backtrace = debug_backtrace();
  if (isset($backtrace[3]) && ($backtrace[3]['function'] == 'drupal_flush_all_caches') && empty($backtrace[3]['args'])) {

Comments

Jānis Bebrītis’s picture

Issue summary: View changes
Jānis Bebrītis’s picture

patch for proposed solution

Jānis Bebrītis’s picture

Status: Active » Needs review
RavindraSingh’s picture

StatusFileSize
new4.53 KB

Before applying the patch, please review https://www.drupal.org/node/2378449
-Performance issue with Breakpoints doubling time for drush cc all

Download https://www.drupal.org/files/issues/2415363-breakpoints-menu_rebuild-13.... patch and apply this.

Change in this patch
breakpoints_themes_enabled(array($theme_key), FALSE);
attiks’s picture

#2378449: Performance issue with Breakpoints doubling time for drush cc all is committed, this patch adds a lot of code style fixes, but needs a reroll

dave reid’s picture

Status: Needs review » Needs work
Yaron Tal’s picture

reroll with these additions:

- Removed $config = breakpoints_settings(); from breakpoints_breakpoint_empty_array() since the output was not used nor was there any static or anything filled.
- Removed "return" from breakpoints_breakpoint_group_delete() and breakpoints_breakpoint_group_delete_by_name() since the function they called (breakpoints_breakpoint_group_delete_by_fullkey()) does not return anything either.

Yaron Tal’s picture

Status: Needs work » Needs review
attiks’s picture

Can somebody review this, so I can commit it?

gugalamaciek’s picture

I applied patch #7, it works - it is invoked during cache clear, but not in system_cron.

attiks’s picture

Status: Needs review » Fixed

Thanks all

  • attiks committed f9f8a99 on 7.x-1.x authored by Yaron Tal
    Issue #2505127 by Jānis Bebrītis, Yaron Tal, RavindraSingh, attiks, Dave...

Status: Fixed » Closed (fixed)

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