Commit afd3112f authored by Leo Gordon's avatar Leo Gordon
Browse files

cache NakedTable objects (without their contents) and Accumulator objects

parent 67124d4c
......@@ -36,7 +36,12 @@ use warnings;
use Bio::EnsEMBL::Hive::Utils ('stringify');
use base ( 'Bio::EnsEMBL::Hive::Storable' );
use base ( 'Bio::EnsEMBL::Hive::Cacheable', 'Bio::EnsEMBL::Hive::Storable' );
sub unikey { # override the default from Cacheable parent
return [ 'struct_name', 'signature_template' ];
}
sub struct_name {
......@@ -104,5 +109,12 @@ sub dataflow {
$self->adaptor->store( \@rows );
}
sub toString {
my $self = shift @_;
return 'Accumulator(' . $self->struct_name . '<--' . $self->signature_template . ')';
}
1;
......@@ -42,7 +42,7 @@ sub collection_of {
$self->{'_cache_by_class'}->{$type} = shift @_;
} elsif (not $self->{'_cache_by_class'}->{$type}) {
if( my $hive_dba = $self->hive_dba ) {
if( (my $hive_dba = $self->hive_dba) and ($type ne 'NakedTable') and ($type ne 'Accumulator') ) {
my $adaptor = $hive_dba->get_adaptor( $type );
my $all_objects = $adaptor->fetch_all();
if(@$all_objects and UNIVERSAL::can($all_objects->[0], 'hive_pipeline') ) {
......@@ -73,25 +73,36 @@ sub find_by_url_query {
return $self->collection_of('Analysis')->find_one_by( $tparam_name, $tparam_value);
} elsif($table_name eq 'accu') {
my $accu;
return Bio::EnsEMBL::Hive::Accumulator->new(
unless($accu = $self->collection_of('Accumulator')->find_one_by( 'struct_name', $tparam_name, 'signature_template', $tparam_value )) {
$accu = $self->add_new_or_update( 'Accumulator',
$self->hive_dba ? (adaptor => $self->hive_dba->get_AccumulatorAdaptor) : (),
struct_name => $tparam_name,
signature_template => $tparam_value,
);
);
}
return $accu;
} elsif($table_name eq 'job') {
die "Jobs cannot yet be found by URLs, sorry";
} else {
my $naked_table;
return Bio::EnsEMBL::Hive::NakedTable->new(
$self->hive_dba ? (adaptor => $self->hive_dba->get_NakedTableAdaptor( 'table_name' => $table_name ) ) : (),
table_name => $table_name,
$tparam_value ? (insertion_method => $tparam_value) : (),
);
unless($naked_table = $self->collection_of('NakedTable')->find_one_by( 'table_name', $table_name )) {
$naked_table = $self->add_new_or_update( 'NakedTable',
$self->hive_dba ? (adaptor => $self->hive_dba->get_NakedTableAdaptor( 'table_name' => $table_name ) ) : (),
table_name => $table_name,
$tparam_value ? (insertion_method => $tparam_value) : (),
);
}
return $naked_table;
}
}
......
......@@ -34,7 +34,12 @@ package Bio::EnsEMBL::Hive::NakedTable;
use strict;
use warnings;
use base ( 'Bio::EnsEMBL::Hive::Storable' );
use base ( 'Bio::EnsEMBL::Hive::Cacheable', 'Bio::EnsEMBL::Hive::Storable' );
sub unikey { # override the default from Cacheable parent
return [ 'table_name' ];
}
sub table_name {
......@@ -77,13 +82,7 @@ sub display_name {
sub dataflow {
my ( $self, $output_ids, $emitting_job ) = @_;
# we have to do this the ugly way
# because Registry code currently prevents us from passing arguments to adaptors' new() methods
# (and by caching guarantees there is only one instance of each adaptor per DBAdaptor)
my $adaptor = $self->adaptor();
$adaptor->table_name( $self->table_name() );
$adaptor->insertion_method( $self->insertion_method() );
my $adaptor = $self->adaptor();
my @column_names = keys %{$self->adaptor->column_set};
my @rows = ();
......@@ -97,5 +96,12 @@ sub dataflow {
$adaptor->store( \@rows );
}
sub toString {
my $self = shift @_;
return 'NakedTable('.$self->table_name.')';
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment