Permalink
Browse files

Try to optimize query by using unique constraint.

  • Loading branch information...
1 parent afdba62 commit 90ebc6a00834ff7cf466dd61ea3c42deb496a2f4 Jeffrey Ryan Thalhammer committed May 18, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/Pinto/Schema/Result/Package.pm
View
8 lib/Pinto/Schema/Result/Package.pm
@@ -196,10 +196,12 @@ sub register {
sub registration {
my ($self, %args) = @_;
- my $where = {name => $args{stack}};
- my $stack = $self->result_source->schema->resultset('Stack')->find($where);
+ my $where1 = {name => $args{stack}};
+ my $stack = $self->result_source->schema->resultset('Stack')->find($where1);
- return $self->find_related('registrations', {stack => $stack});
+ my $attrs = {key => 'stack_package_name_unique'};
+ my $where2 = {stack => $stack, package_name => $self->name};
+ return $self->find_related('registrations', $where2, $attrs);
}
#------------------------------------------------------------------------------

0 comments on commit 90ebc6a

Please sign in to comment.