diff --git a/src/MGRAST/lib/resources2/matrix.pm b/src/MGRAST/lib/resources2/matrix.pm index c6d94867..8a815dcf 100644 --- a/src/MGRAST/lib/resources2/matrix.pm +++ b/src/MGRAST/lib/resources2/matrix.pm @@ -226,14 +226,9 @@ sub instance { $self->return_data( {"ERROR" => "no valid ids submitted and/or found: ".join(", ", @ids)}, 401 ); } - # get cached if exists - my $cached = $self->memd->get($self->url_id); - if ($cached) { - # do a runaround on ->return_data - print $self->header; - print $cached; - exit 0; - } + # return cached if exists + $self->return_cached(); + # prepare data my $data = $self->prepare_data([keys %$mgids], $type); $self->return_data($data, undef, 1); # cache this! @@ -257,7 +252,7 @@ sub prepare_data { my $leaf_node = 0; my $matrix_id = join("_", sort @$data).'_'.join("_", ($type, $glvl, $source, $rtype, $eval, $ident, $alen)); if (@filter > 0) { - $matrix_id .= join("_", sort map { $_ =~ s/\s+/_/ } @filter)."_".$fsrc; + $matrix_id .= join("_", sort map { $_ =~ s/\s+/_/g } @filter)."_".$fsrc; } # initialize analysis obj with mgids diff --git a/src/MGRAST/lib/resources2/metagenome.pm b/src/MGRAST/lib/resources2/metagenome.pm index aa92c560..9734aa88 100644 --- a/src/MGRAST/lib/resources2/metagenome.pm +++ b/src/MGRAST/lib/resources2/metagenome.pm @@ -123,14 +123,9 @@ sub instance { $self->return_data( {"ERROR" => "insufficient permissions to view this data"}, 401 ); } - # get cached if exists - my $cached = $self->memd->get($self->url_id); - if ($cached) { - # do a runaround on ->return_data - print $self->header; - print $cached; - exit 0; - } + # return cached if exists + $self->return_cached(); + # prepare data my $data = $self->prepare_data( [$job] ); $data = $data->[0]; diff --git a/src/MGRAST/lib/resources2/project.pm b/src/MGRAST/lib/resources2/project.pm index edf57871..90366587 100644 --- a/src/MGRAST/lib/resources2/project.pm +++ b/src/MGRAST/lib/resources2/project.pm @@ -117,14 +117,9 @@ sub instance { $self->return_data( {"ERROR" => "insufficient permissions to view this data"}, 401 ); } - # get cached if exists - my $cached = $self->memd->get($self->url_id); - if ($cached) { - # do a runaround on ->return_data - print $self->header; - print $cached; - exit 0; - } + # return cached if exists + $self->return_cached(); + # prepare data my $data = $self->prepare_data( [$project] ); $data = $data->[0]; diff --git a/src/MGRAST/lib/resources2/resource.pm b/src/MGRAST/lib/resources2/resource.pm index a3ac79a5..d7cc0571 100644 --- a/src/MGRAST/lib/resources2/resource.pm +++ b/src/MGRAST/lib/resources2/resource.pm @@ -235,6 +235,19 @@ sub check_pagination { } } +# return cached data if exists +sub return_cached { + my ($self) = @_; + + my $cached = $self->memd->get($self->url_id); + if ($cached) { + # do a runaround on ->return_data + print $self->header; + print $cached; + exit 0; + } +} + # print the actual data output sub return_data { my ($self, $data, $error, $cache_me) = @_; @@ -468,6 +481,14 @@ sub get_shock_query { } } +# I can't find a perl library that gives me random UUID ! +sub uuidv4 { + my ($self) = @_; + my $uuid = `python -c "import uuid; print uuid.uuid4()"`; + chomp $uuid; + return $uuid; +} + sub toFloat { my ($self, $x) = @_; return $x * 1.0;