function apdqc_views_pre_build in Asynchronous Prefetch Database Query Cache 7
Implements hook_views_pre_build().
File
- ./
apdqc.module, line 784 - Asynchronous Prefetch Database Query Cache module.
Code
function apdqc_views_pre_build($view) {
if (!function_exists('apdqc_run_prefetch_array') || !function_exists('apdqc_escape_string')) {
return;
}
static $run_once;
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') {
$table_keys_cache_prefetch['cache_views'][] = 'ctools_export:views_view:' . $view->name;
}
foreach ($view->display as $values) {
// Get field data.
if (!empty($values->handler->options['fields'])) {
foreach ($values->handler->options['fields'] as $field_name => $info) {
if (apdqc_get_bin_class_name('cache_views') === 'APDQCache') {
if (strpos($field_name, 'field_') === 0) {
if (empty($run_once['field_data_' . $field_name])) {
$table_keys_cache_prefetch['cache_views'][] = 'views_data:field_data_' . apdqc_escape_string($field_name) . ':' . $lang_shorthand;
$run_once['field_data_' . $field_name] = TRUE;
}
}
}
if (apdqc_get_bin_class_name('cache') === 'APDQCache') {
// One off for VBO.
if ($field_name == 'views_bulk_operations' && empty($run_once['ctools_plugin_files:views_bulk_operations:operation_types'])) {
$table_keys_cache_prefetch['cache'][] = 'ctools_plugin_files:views_bulk_operations:operation_types';
$run_once['ctools_plugin_files:views_bulk_operations:operation_types'] = TRUE;
}
}
}
}
if (apdqc_get_bin_class_name('cache_views') === 'APDQCache') {
// Get table data.
if (!empty($values->handler->options['filters'])) {
foreach ($values->handler->options['filters'] as $info) {
if (empty($run_once[$info['table']])) {
$table_keys_cache_prefetch['cache_views'][] = 'views_data:' . apdqc_escape_string($info['table']) . ':' . $lang_shorthand;
$run_once[$info['table']] = TRUE;
}
}
}
}
}
if (apdqc_get_bin_class_name('cache_field') === 'APDQCache') {
if (!empty($view->display_handler->handlers['field'])) {
foreach ($view->display_handler->handlers['field'] as $values) {
if (isset($values->field_info['bundles'])) {
foreach ($values->field_info['bundles'] as $entity_name => $entity_types) {
foreach ($entity_types as $entity_type) {
$table_keys_cache_prefetch['cache_field'][] = "field_info:bundle:{$entity_name}:{$entity_type}";
}
}
}
}
}
}
if (apdqc_get_bin_class_name('cache_views') === 'APDQCache') {
if (empty($run_once[$view->name])) {
$table_keys_cache_prefetch['cache_views'][] = 'ctools_export:views_view:' . apdqc_escape_string($view->name);
$run_once[$view->name] = TRUE;
}
}
// Prefetch cache.
apdqc_run_prefetch_array($table_keys_cache_prefetch);
}