Browse Source

Merge pull request #695 from tripal/tv3-cache_terms

Cache terms to improve the performance of page load
Lacey-Anne Sanderson 6 năm trước cách đây
mục cha
commit
35f7172637

+ 5 - 2
tripal_chado/includes/TripalImporter/OBOImporter.inc

@@ -575,8 +575,11 @@ class OBOImporter extends TripalImporter {
    *
    */
   public function postRun() {
+    
+    // Clear the cached terms
+    cache_clear_all('tripal_chado:term:*', 'cache', TRUE);
 
-    // Update the cv_root_mview materiailzed view.
+    // Update the cv_root_mview materialized view.
     $this->logMessage("Updating the cv_root_mview materialized view...");
     $mview_id = tripal_get_mview_id('cv_root_mview');
     tripal_populate_mview($mview_id);
@@ -585,7 +588,7 @@ class OBOImporter extends TripalImporter {
     $mview_id = tripal_get_mview_id('db2cv_mview');
     tripal_populate_mview($mview_id);
 
-    // Upate the cvtermpath table for each newly added CV.
+    // Update the cvtermpath table for each newly added CV.
     $this->logMessage("Updating cvtermpath table.  This may take a while...");
     foreach ($this->obo_namespaces as $namespace => $cv_id) {
       $this->logMessage("- Loading paths for vocabulary: @vocab", array('@vocab' => $namespace));

+ 4 - 0
tripal_chado/includes/tripal_chado.cv.inc

@@ -154,6 +154,10 @@ function tripal_cv_cv_edit_form_submit($form, &$form_state) {
   if (strcmp($op, 'Update')==0) {
     $match = array('cv_id' => $cv_id);
     $success = chado_update_record('cv', $match, $values);
+    
+    // Clear the cached terms
+    cache_clear_all('tripal_chado:term:*', 'cache', TRUE);
+    
     if ($success) {
       drupal_set_message(t("Controlled vocabulary updated"));
       drupal_goto('admin/tripal/loaders/chado_vocabs/chado_cvs');

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

@@ -257,7 +257,14 @@ 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) {
-
+  // Cache ID for this term:
+  $cid = 'tripal_chado:term:' . $vocabulary . ':' . $accession;
+  
+  // Check the cache first. Get the term from cache if it's available
+  $cache = cache_get($cid, 'cache');
+  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 +292,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($cid, $term, 'cache', CACHE_TEMPORARY);
+  return $term;
 }
 
 /**