You are here

function apdqc_views_pre_view in Asynchronous Prefetch Database Query Cache 7

Implements hook_views_pre_view().

File

./apdqc.module, line 716
Asynchronous Prefetch Database Query Cache module.

Code

function apdqc_views_pre_view($view) {
  if (!function_exists('apdqc_run_prefetch_array') || !function_exists('apdqc_escape_string')) {
    return;
  }
  static $lang_shorthand;
  if (!isset($lang_shorthand)) {
    $lang_shorthand = apdqc_get_lang();
  }
  $table_keys_cache_prefetch = array();
  if (apdqc_get_bin_class_name('cache_views') === 'APDQCache') {
    if (!empty($view->relationship)) {
      foreach ($view->relationship as $values) {
        if (!empty($values->table)) {
          $table_keys_cache_prefetch['cache_views'][] = "views_data:{$values->table}:{$lang_shorthand}";
        }
      }
    }
    if (!empty($view->filter)) {
      foreach ($view->filter as $values) {
        if (!empty($values->table)) {
          $table_keys_cache_prefetch['cache_views'][] = "views_data:{$values->table}:{$lang_shorthand}";
        }
      }
    }
    if (!empty($view->display_handler->display->display_options['relationships'])) {
      foreach ($view->display_handler->display->display_options['relationships'] as $values) {
        if (!empty($values['table'])) {
          $table_keys_cache_prefetch['cache_views'][] = "views_data:{$values['table']}:{$lang_shorthand}";
        }
      }
    }
    if (!empty($view->display_handler->default_display->options['relationships'])) {
      foreach ($view->display_handler->default_display->options['relationships'] as $values) {
        if (!empty($values['table'])) {
          $table_keys_cache_prefetch['cache_views'][] = "views_data:{$values['table']}:{$lang_shorthand}";
        }
      }
    }
    if (!empty($view->display_handler->options['filters'])) {
      foreach ($view->display_handler->options['filters'] as $values) {
        if (!empty($values['table'])) {
          $table_keys_cache_prefetch['cache_views'][] = "views_data:{$values['table']}:{$lang_shorthand}";
        }
      }
    }
    if (!empty($view->display['default']->display_options['filters'])) {
      foreach ($view->display['default']->display_options['filters'] as $values) {
        if (!empty($values['table'])) {
          $table_keys_cache_prefetch['cache_views'][] = "views_data:{$values['table']}:{$lang_shorthand}";
        }
      }
    }
  }

  // Prefetch cache.
  apdqc_run_prefetch_array($table_keys_cache_prefetch);
}