You are here

function apdqc_views_post_execute in Asynchronous Prefetch Database Query Cache 7

Implements hook_views_post_execute().

File

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

Code

function apdqc_views_post_execute($view) {
  if (!function_exists('apdqc_run_prefetch_array') || !function_exists('apdqc_escape_string')) {
    return;
  }
  if (apdqc_get_bin_class_name('cache_field') !== 'APDQCache') {
    return;
  }

  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['cache_field'] =& drupal_static('apdqc_cache_prefetch_ids');
  }
  $table_keys_cache_prefetch = array();
  foreach ($view->result as $row) {
    if (isset($row->nid)) {
      $string = 'field:node:' . apdqc_escape_string($row->nid);
      if (!isset($drupal_static_fast['cache_field'][$string])) {
        $drupal_static_fast['cache_field'][$string] = TRUE;
        $table_keys_cache_prefetch['cache_field'][] = $string;
      }
    }
  }

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