Skip to content
Snippets Groups Projects
Commit dbc6f7dc authored by Andy Yates's avatar Andy Yates
Browse files

[ENSCORESW-577]. Additional lookup would not work if it was the first call.

The code did not attempt to build the additional lookup before fetching from
it. Our solution is to switch to requesting the cache in get_????_additional_lookup()
which will trigger the building of the additional lookup.
parent a9dbfd65
No related branches found
No related tags found
No related merge requests found
...@@ -125,6 +125,7 @@ sub clear_cache { ...@@ -125,6 +125,7 @@ sub clear_cache {
sub get_by_additional_lookup { sub get_by_additional_lookup {
my ($self, $key, $value) = @_; my ($self, $key, $value) = @_;
$self->cache(); # trigger cache building
my $additional_lookup = $self->_additional_lookup(); my $additional_lookup = $self->_additional_lookup();
if(exists $additional_lookup->{$key}) { if(exists $additional_lookup->{$key}) {
if(exists $additional_lookup->{$key}->{$value}) { if(exists $additional_lookup->{$key}->{$value}) {
...@@ -158,6 +159,7 @@ sub get_by_additional_lookup { ...@@ -158,6 +159,7 @@ sub get_by_additional_lookup {
sub get_all_by_additional_lookup { sub get_all_by_additional_lookup {
my ($self, $key, $value) = @_; my ($self, $key, $value) = @_;
$self->cache(); # trigger cache building
my $additional_lookup = $self->_additional_lookup(); my $additional_lookup = $self->_additional_lookup();
if(exists $additional_lookup->{$key}) { if(exists $additional_lookup->{$key}) {
if(exists $additional_lookup->{$key}->{$value}) { if(exists $additional_lookup->{$key}->{$value}) {
......
...@@ -105,6 +105,16 @@ sub BEGIN { ...@@ -105,6 +105,16 @@ sub BEGIN {
dies_ok { $cache->get_by_additional_lookup('biotype', 'protein_coding') } 'Expect to die as the query will return more than one value'; dies_ok { $cache->get_by_additional_lookup('biotype', 'protein_coding') } 'Expect to die as the query will return more than one value';
#Clear the cache and make sure that we can still retrieve by additional values
{
$cache->clear_cache();
my $db_id = $protein_coding_genes->[0]->dbID();
my $fetched_gene = $cache->get_by_additional_lookup('dbID', $db_id);
ok(defined $fetched_gene, 'Checking we got a gene back if we fetched using additional lookups alone');
cmp_ok($fetched_gene->dbID(), '==', $db_id, 'Checking we got a gene back if we fetched using additional lookups alone');
}
$cache->remove($individual_gene->dbID()); $cache->remove($individual_gene->dbID());
my $new_protein_coding_genes = $cache->get_all_by_additional_lookup('biotype', 'protein_coding'); my $new_protein_coding_genes = $cache->get_all_by_additional_lookup('biotype', 'protein_coding');
......
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