You are here

function apdqc_entity_load in Asynchronous Prefetch Database Query Cache 7

Implements hook_entity_load().

File

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

Code

function apdqc_entity_load($entities, $type) {
  if (!function_exists('apdqc_run_prefetch_array') || !function_exists('apdqc_escape_string')) {
    return;
  }
  if (apdqc_get_bin_class_name('cache_field') !== 'APDQCache') {
    return;
  }
  $bundle_type = apdqc_escape_string($type);
  $table_keys_cache_prefetch = array();
  foreach ($entities as $entity) {
    if (!is_object($entity) || empty($entity->type)) {
      continue;
    }
    $type = apdqc_escape_string($entity->type);
    $table_keys_cache_prefetch['cache_field'][] = "field_info:bundle:{$bundle_type}:{$type}";
    $table_keys_cache_prefetch['cache_field'][] = "field_info:bundle_extra:{$bundle_type}:{$type}";
    foreach ($entity as $key => $fields) {
      if (strpos($key, 'field_') !== 0 || empty($fields[LANGUAGE_NONE])) {
        continue;
      }
      foreach ($fields[LANGUAGE_NONE] as $values) {
        if (empty($values['entity']) || !is_object($values['entity']) || empty($values['entity']->type)) {
          continue;
        }
        $type = apdqc_escape_string($values['entity']->type);
        $table_keys_cache_prefetch['cache_field'][] = "field_info:bundle:{$bundle_type}:{$type}";
        $table_keys_cache_prefetch['cache_field'][] = "field_info:bundle_extra:{$bundle_type}:{$type}";
      }
    }
  }

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