Browse Source

Fixed bug in MViews where the index was not being created properly. The index should have been made for each field individually in the argument. However, it was creating a single 'unique' index using all values. This kept some materialized views from being populated.

stephen 13 years ago
parent
commit
2e0a6e620d
1 changed files with 2 additions and 8 deletions
  1. 2 8
      base/tripal_core/mviews.php

+ 2 - 8
base/tripal_core/mviews.php

@@ -58,14 +58,11 @@ function tripal_add_mview ($name,$modulename,$mv_table,$mv_specs,$indexed,$query
       // now construct the indexes
       // now construct the indexes
       $index = '';
       $index = '';
       if($indexed){
       if($indexed){
-         // remove extra spaces and index field names
-        $indexed = preg_replace("/\s+,/",",",$indexed);
-        $indexed = preg_replace("/\s+\n/","\n",$indexed);
-        $indexed = preg_replace("/,\n/","\n",$indexed);
         // add to the array of values
         // add to the array of values
         $vals = preg_split("/[\n,]+/",$indexed);
         $vals = preg_split("/[\n,]+/",$indexed);
         $index = '';
         $index = '';
         foreach ($vals as $field){
         foreach ($vals as $field){
+           $field = trim($field);
            $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
            $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
         }
         }
       }
       }
@@ -149,14 +146,11 @@ function tripal_edit_mview ($mview_id,$name,$modulename,$mv_table,$mv_specs,$ind
       // now construct the indexes
       // now construct the indexes
       $index = '';
       $index = '';
       if($indexed){
       if($indexed){
-         // remove extra spaces and index field names
-        $indexed = preg_replace("/\s+,/",",",$indexed);
-        $indexed = preg_replace("/\s+\n/","\n",$indexed);
-        $indexed = preg_replace("/,\n/","\n",$indexed);
         // add to the array of values
         // add to the array of values
         $vals = preg_split("/[\n,]+/",$indexed);
         $vals = preg_split("/[\n,]+/",$indexed);
         $index = '';
         $index = '';
         foreach ($vals as $field){
         foreach ($vals as $field){
+           $field = trim($field);
            $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
            $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
         }
         }
       }
       }