Explorar el Código

Cache terms to improve performance

Chun-Huai Cheng hace 6 años
padre
commit
e9f5d3485b
Se han modificado 1 ficheros con 10 adiciones y 2 borrados
  1. 10 2
      tripal_chado/includes/tripal_chado.vocab_storage.inc

+ 10 - 2
tripal_chado/includes/tripal_chado.vocab_storage.inc

@@ -257,7 +257,12 @@ function tripal_chado_vocab_get_term_children($vocabulary, $accession) {
  * This hook is created by the Tripal module and is not a Drupal hook.
  */
 function tripal_chado_vocab_get_term($vocabulary, $accession) {
-
+  
+  // Check the cache fisrt. Get the term from cache if it's available
+  $cache = cache_get('tripal_chado:term:' . $vocabulary . ':' . $accession);
+  if (isset($cache->data)) {
+    return $cache->data;
+  }
   // It's possible that Chado is not available (i.e. it gets renamed
   // for copying) but Tripal has already been prepared and the
   // entities exist.  If this is the case we don't want to run the
@@ -285,7 +290,10 @@ function tripal_chado_vocab_get_term($vocabulary, $accession) {
   $cvterm = chado_expand_var($cvterm, 'table', 'cvterm_relationship', $options);
   $cvterm = chado_expand_var($cvterm, 'table', 'cvtermprop', $options);
 
-  return _tripal_chado_format_term_description($cvterm);
+  // Cache the term to reduce the amount of queries sent to the database
+  $term =  _tripal_chado_format_term_description($cvterm);
+  cache_set('tripal_chado:term:' . $vocabulary . ':' . $accession, $term);
+  return $term;
 }
 
 /**