From: Tara L Andrews Date: Wed, 24 Apr 2013 09:47:16 +0000 (+0200) Subject: invalidate alignment table cache on relationship add if appropriate X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=864ee4bf9b544da4cd986b1247f9578552b4e4fc;hp=b39e7cb5cc6b77a19cac9bd83bf23105d8f75cc4;p=scpubgit%2Fstemmatology.git invalidate alignment table cache on relationship add if appropriate --- diff --git a/base/lib/Text/Tradition/Collation.pm b/base/lib/Text/Tradition/Collation.pm index a2843e4..2576646 100644 --- a/base/lib/Text/Tradition/Collation.pm +++ b/base/lib/Text/Tradition/Collation.pm @@ -535,7 +535,15 @@ sub add_relationship { my $self = shift; my( $source, $target, $opts ) = $self->_stringify_args( @_ ); my( @vectors ) = $self->relations->add_relationship( $source, $target, $opts ); - $self->_graphcalc_done(0); + foreach my $v ( @vectors ) { + next unless $self->get_relationship( $v )->colocated; + if( $self->reading( $v->[0] )->has_rank && $self->reading( $v->[1] )->has_rank + && $self->reading( $v->[0] )->rank ne $self->reading( $v->[1] )->rank ) { + $self->_graphcalc_done(0); + $self->_clear_cache; + last; + } + } return @vectors; } @@ -1574,8 +1582,10 @@ ok( $c->has_cached_table, "Alignment table was cached" ); is( $c->alignment_table, $table, "Cached table returned upon second call" ); $c->calculate_ranks; is( $c->alignment_table, $table, "Cached table retained with no rank change" ); -$c->add_relationship( 'n24', 'n23', { 'type' => 'spelling' } ); -isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" ); +$c->add_relationship( 'n13', 'n23', { type => 'repetition' } ); +is( $c->alignment_table, $table, "Alignment table unchanged after non-colo relationship add" ); +$c->add_relationship( 'n24', 'n23', { type => 'spelling' } ); +isnt( $c->alignment_table, $table, "Alignment table changed after colo relationship add" ); =end testing diff --git a/base/t/text_tradition_collation.t b/base/t/text_tradition_collation.t index 9e998c6..6f5041c 100644 --- a/base/t/text_tradition_collation.t +++ b/base/t/text_tradition_collation.t @@ -117,8 +117,10 @@ ok( $c->has_cached_table, "Alignment table was cached" ); is( $c->alignment_table, $table, "Cached table returned upon second call" ); $c->calculate_ranks; is( $c->alignment_table, $table, "Cached table retained with no rank change" ); -$c->add_relationship( 'n24', 'n23', { 'type' => 'spelling' } ); -isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" ); +$c->add_relationship( 'n13', 'n23', { type => 'repetition' } ); +is( $c->alignment_table, $table, "Alignment table unchanged after non-colo relationship add" ); +$c->add_relationship( 'n24', 'n23', { type => 'spelling' } ); +isnt( $c->alignment_table, $table, "Alignment table changed after colo relationship add" ); }