Add eager fetching of relations and enable that for jobset->jobsetinputs
Signed-off-by: Shea Levy <shea@shealevy.com>
This commit is contained in:
		| @@ -23,6 +23,11 @@ sub TO_JSON { | |||||||
|             $json{$relname} = [ map { $_->$key } $self->$relname ]; |             $json{$relname} = [ map { $_->$key } $self->$relname ]; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         foreach my $relname (keys %{$hint->{eager_relations}}) { | ||||||
|  |             my $key = $hint->{eager_relations}->{$relname}; | ||||||
|  |             $json{$relname} = { map { $_->$key => $_ } $self->$relname }; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         return \%json; |         return \%json; | ||||||
|     } else { |     } else { | ||||||
|         my $json = { $self->get_columns }; |         my $json = { $self->get_columns }; | ||||||
|   | |||||||
| @@ -153,4 +153,14 @@ __PACKAGE__->has_many( | |||||||
| # Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-10-08 13:06:15 | # Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-10-08 13:06:15 | ||||||
| # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+mZZqLjQNwblb/EWW1alLQ | # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+mZZqLjQNwblb/EWW1alLQ | ||||||
|  |  | ||||||
|  | my %hint = ( | ||||||
|  |     relations => { | ||||||
|  |         "jobsetinputalts" => "value" | ||||||
|  |     } | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | sub json_hint { | ||||||
|  |     return \%hint; | ||||||
|  | } | ||||||
|  |  | ||||||
| 1; | 1; | ||||||
|   | |||||||
| @@ -309,7 +309,7 @@ __PACKAGE__->has_many( | |||||||
| # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DTAGxP5RFvcNxP/ciJGo4Q | # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DTAGxP5RFvcNxP/ciJGo4Q | ||||||
|  |  | ||||||
| my %hint = ( | my %hint = ( | ||||||
|     relations => { |     eager_relations => { | ||||||
|         jobsetinputs => "name" |         jobsetinputs => "name" | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| use LWP::UserAgent; | use LWP::UserAgent; | ||||||
| use JSON; | use JSON; | ||||||
| use Test::Simple tests => 9; | use Test::Simple tests => 10; | ||||||
| #use Test::Simple tests => 15; | #use Test::Simple tests => 15; | ||||||
|  |  | ||||||
| my $ua = LWP::UserAgent->new; | my $ua = LWP::UserAgent->new; | ||||||
| @@ -43,12 +43,12 @@ ok($result->code() == 201, "PUTting a new jobset creates it"); | |||||||
|  |  | ||||||
| my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content()); | my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content()); | ||||||
|  |  | ||||||
| ok($jobset->{jobsetinputs}->[0] eq "my-src", "The new jobset has a 'my-src' input"); | ok(exists $jobset->{jobsetinputs}->{"my-src"}, "The new jobset has a 'my-src' input"); | ||||||
|  |  | ||||||
|  | ok($jobset->{jobsetinputs}->{"my-src"}->{jobsetinputalts}->[0] eq "/run/jobset", "The 'my-src' input is in /run/jobset"); | ||||||
|  |  | ||||||
| =begin comment | =begin comment | ||||||
|  |  | ||||||
| ok($jobset->{jobsetinputs}->[0]->{jobsetinputalts}->[0]->{value} eq "/run/jobset", "The 'my-src' input is in /run/jobset"); |  | ||||||
|  |  | ||||||
| system("LOGNAME=root NIX_STORE_DIR=/run/nix/store NIX_LOG_DIR=/run/nix/var/log/nix NIX_STATE_DIR=/run/nix/var/nix HYDRA_DATA=/var/lib/hydra HYDRA_DBI='dbi:Pg:dbname=hydra;user=root;' hydra-evaluator sample default"); | system("LOGNAME=root NIX_STORE_DIR=/run/nix/store NIX_LOG_DIR=/run/nix/var/log/nix NIX_STATE_DIR=/run/nix/var/nix HYDRA_DATA=/var/lib/hydra HYDRA_DBI='dbi:Pg:dbname=hydra;user=root;' hydra-evaluator sample default"); | ||||||
| $result = request_json({ uri => '/jobset/sample/default/evals' }); | $result = request_json({ uri => '/jobset/sample/default/evals' }); | ||||||
| ok($result->code() == 200, "Can get evals of a jobset"); | ok($result->code() == 200, "Can get evals of a jobset"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user