From a032c47caf9933b8ea7f2365c5e5f6c88d5723a5 Mon Sep 17 00:00:00 2001
From: Graham McVicker <mcvicker@sanger.ac.uk>
Date: Fri, 13 Aug 2004 15:30:14 +0000
Subject: [PATCH] max feature length can be overridden, allows optimization for
 misc feature retrieval

---
 .../Bio/EnsEMBL/DBSQL/BaseFeatureAdaptor.pm   | 19 +++++++++++++++++--
 .../Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm   | 11 ++++++++++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/modules/Bio/EnsEMBL/DBSQL/BaseFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/BaseFeatureAdaptor.pm
index a76129a17d..87a7fa896c 100644
--- a/modules/Bio/EnsEMBL/DBSQL/BaseFeatureAdaptor.pm
+++ b/modules/Bio/EnsEMBL/DBSQL/BaseFeatureAdaptor.pm
@@ -492,7 +492,7 @@ sub _slice_fetch {
     if($feat_cs->equals($slice_cs)) {
       # no mapping is required if this is the same coord system
 
-      my $max_len =
+      my $max_len = $self->_max_feature_length() ||
         $mcc->fetch_max_length_by_CoordSystem_feature_type($feat_cs,$tab_name);
 
       my $constraint = $orig_constraint;
@@ -552,7 +552,7 @@ sub _slice_fetch {
       } else {
         # do multiple split queries using start / end constraints
 
-        my $max_len =
+        my $max_len = $self->_max_feature_length() ||
           $mcc->fetch_max_length_by_CoordSystem_feature_type($feat_cs,
                                                              $tab_name);
         my $len = @coords;
@@ -1044,6 +1044,21 @@ sub _objs_from_sth {
 }
 
 
+
+#
+# Internal function. Allows the max feature length which is normally
+# retrieved from the meta_coord table to be overridden.  This allows
+# for some significant optimizations to be put in when it is known
+# that requested features will not be over a certain size.
+#
+sub _max_feature_length {
+  my $self = shift;
+  return $self->{'_max_feature_length'} = shift if(@_);
+  return $self->{'_max_feature_length'};
+}
+
+
+
 =head1 DEPRECATED METHODS
 
 =cut
diff --git a/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm
index ea1baf56de..c62ad8a902 100644
--- a/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm
+++ b/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm
@@ -87,8 +87,10 @@ sub fetch_all_by_Slice_and_set_code {
 
   my $msa = $self->db->get_MiscSetAdaptor();
   my @sets = ();
+  my $max_len = 0;
   foreach my $set_code (@_) {
     my $set = $msa->fetch_by_code($set_code);
+    $max_len = $set->longest_feature() if($set->longest_feature > $max_len);
     if(!$set) { warning("No misc_set with code [$set_code] exists") }
     else { push @sets, $set->dbID; }
   }
@@ -100,7 +102,14 @@ sub fetch_all_by_Slice_and_set_code {
   } else {
     return [];
   }
-  return $self->fetch_all_by_Slice_constraint($slice, $constraint);
+
+  $self->_max_feature_length($max_len);
+
+  my $results = $self->fetch_all_by_Slice_constraint($slice, $constraint);
+
+  $self->_max_feature_length(undef);
+
+  return $results;
 }
 
 
-- 
GitLab