From: Peter Rabbitson Date: Tue, 15 Dec 2015 22:22:51 +0000 (+0100) Subject: Reduce duplicate ->result_source calls where sensible X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5567c8f84ba0c2d620191cc8ac956b0b5630ca00;p=dbsrgits%2FDBIx-Class-Historic.git Reduce duplicate ->result_source calls where sensible No functional changes --- diff --git a/lib/DBIx/Class/Ordered.pm b/lib/DBIx/Class/Ordered.pm index 8b84bd4..0c572e8 100644 --- a/lib/DBIx/Class/Ordered.pm +++ b/lib/DBIx/Class/Ordered.pm @@ -364,8 +364,10 @@ sub move_to { my $position_column = $self->position_column; + my $rsrc = $self->result_source; + my $is_txn; - if ($is_txn = $self->result_source->schema->storage->transaction_depth) { + if ($is_txn = $rsrc->schema->storage->transaction_depth) { # Reload position state from storage # The thinking here is that if we are in a transaction, it is # *more likely* the object went out of sync due to resultset @@ -375,8 +377,7 @@ sub move_to { $self->store_column( $position_column, - ( $self->result_source - ->resultset + ( $rsrc->resultset ->search($self->_storage_ident_condition, { rows => 1, columns => $position_column }) ->cursor ->next @@ -400,7 +401,7 @@ sub move_to { return 0; } - my $guard = $is_txn ? undef : $self->result_source->schema->txn_scope_guard; + my $guard = $is_txn ? undef : $rsrc->schema->txn_scope_guard; my ($direction, @between); if ( $from_position < $to_position ) { @@ -415,7 +416,7 @@ sub move_to { my $new_pos_val = $self->_position_value ($to_position); # record this before the shift # we need to null-position the moved row if the position column is part of a constraint - if (grep { $_ eq $position_column } ( map { @$_ } (values %{{ $self->result_source->unique_constraints }} ) ) ) { + if (grep { $_ eq $position_column } ( map { @$_ } (values %{{ $rsrc->unique_constraints }} ) ) ) { $self->_ordered_internal_update({ $position_column => $self->null_position_value }); } diff --git a/lib/DBIx/Class/Relationship/Accessor.pm b/lib/DBIx/Class/Relationship/Accessor.pm index 40deeaf..e34294d 100644 --- a/lib/DBIx/Class/Relationship/Accessor.pm +++ b/lib/DBIx/Class/Relationship/Accessor.pm @@ -35,7 +35,9 @@ sub add_relationship_accessor { return $self->{_relationship_data}{%1$s}; } else { - my $relcond = $self->result_source->_resolve_relationship_condition( + my $rsrc = $self->result_source; + + my $relcond = $rsrc->_resolve_relationship_condition( rel_name => %1$s, foreign_alias => %1$s, self_alias => 'me', @@ -49,7 +51,7 @@ sub add_relationship_accessor { and scalar grep { not defined $_ } values %%{ $relcond->{join_free_condition} || {} } and - $self->result_source->relationship_info(%1$s)->{attrs}{undef_on_null_fk} + $rsrc->relationship_info(%1$s)->{attrs}{undef_on_null_fk} ); my $val = $self->search_related( %1$s )->single; diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 0b1f9fa..9030712 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -838,7 +838,7 @@ sub find { if (defined $constraint_name) { $final_cond = $self->_qualify_cond_columns ( - $self->result_source->_minimal_valueset_satisfying_constraint( + $rsrc->_minimal_valueset_satisfying_constraint( constraint_name => $constraint_name, values => ($self->_merge_with_rscond($call_cond))[0], carp_on_nulls => 1, @@ -875,10 +875,10 @@ sub find { dbic_internal_try { push @unique_queries, $self->_qualify_cond_columns( - $self->result_source->_minimal_valueset_satisfying_constraint( + $rsrc->_minimal_valueset_satisfying_constraint( constraint_name => $c_name, values => ($self->_merge_with_rscond($call_cond))[0], - columns_info => ($ci ||= $self->result_source->columns_info), + columns_info => ($ci ||= $rsrc->columns_info), ), $alias ); @@ -2215,6 +2215,8 @@ sub populate { # FIXME - no cref handling # At this point assume either hashes or arrays + my $rsrc = $self->result_source; + if(defined wantarray) { my (@results, $guard); @@ -2222,7 +2224,7 @@ sub populate { # column names only, nothing to do return if @$data == 1; - $guard = $self->result_source->schema->storage->txn_scope_guard + $guard = $rsrc->schema->storage->txn_scope_guard if @$data > 2; @results = map @@ -2232,7 +2234,7 @@ sub populate { } else { - $guard = $self->result_source->schema->storage->txn_scope_guard + $guard = $rsrc->schema->storage->txn_scope_guard if @$data > 1; @results = map { $self->new_result($_)->insert } @$data; @@ -2246,7 +2248,6 @@ sub populate { # this means we have to walk the data structure twice # whether we want this or not # jnap, I hate you ;) - my $rsrc = $self->result_source; my $rel_info = { map { $_ => $rsrc->relationship_info($_) } $rsrc->relationships }; my ($colinfo, $colnames, $slices_with_rels); diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index c8b57b6..8ce9310 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -372,8 +372,7 @@ sub insert { my $existing; # if there are no keys - nothing to search for - if (keys %$them and $existing = $self->result_source - ->related_source($rel_name) + if (keys %$them and $existing = $rsrc->related_source($rel_name) ->resultset ->find($them) ) { @@ -891,15 +890,18 @@ sub get_inflated_columns { sub _is_column_numeric { my ($self, $column) = @_; - return undef unless $self->result_source->has_column($column); + my $rsrc; - my $colinfo = $self->result_source->column_info ($column); + return undef + unless ( $rsrc = $self->result_source )->has_column($column); + + my $colinfo = $rsrc->column_info ($column); # cache for speed (the object may *not* have a resultsource instance) if ( ! defined $colinfo->{is_numeric} and - my $storage = dbic_internal_try { $self->result_source->schema->storage } + my $storage = dbic_internal_try { $rsrc->schema->storage } ) { $colinfo->{is_numeric} = $storage->is_datatype_numeric ($colinfo->{data_type})