$self->app->home->rel_dir('data') . '/' . $path . '.changes';
}
+sub _hash_eq {
+ my ( $a_ref, $b_ref ) = @_;
+
+ warn "# _hash_eq ",dump($a_ref,$b_ref);
+
+ local $Storable::canonical = 1;
+ return eval { Storable::freeze( $a_ref ) } eq eval { Storable::freeze( $b_ref ) };
+}
+
sub index {
my ( $self ) = @_;
my $path = $self->param('path') || $self->session('path');
my $on_path = $self->param('on_path');
my $commit = $self->param('commit');
+ my $apply = $self->param('apply');
my ( $items, $unique2id );
if ( $on_path ) {
$items = $MojoFacets::Data::loaded->{$on_path}->{data}->{items};
if ( ! $items ) {
warn "$on_path not loaded";
- $self->redirect_to('/data/index?path=' . $on_path);
- return;
+ return $self->redirect_to('/data/index?path=' . $on_path);
}
warn "using ", $#$items + 1, " items from $on_path\n";
}
my $changes;
my $stats;
my $glob = $self->_changes_path . '/*';
+ my $status = 'unknown';
foreach my $t ( sort { $a cmp $b } glob $glob ) {
my $e = retrieve($t);
$e->{old} = [ $e->{old} ] unless ref $e->{old} eq 'ARRAY';
$unique2id->{$pk}->{ $items->[$i]->{$pk}->[0] } = $i;
}
}
- my $status = 'missing';
+ $status = 'missing';
if ( my $i = $unique2id->{$pk}->{$id} ) {
- $status = 'found';
- if ( $commit ) {
- my $column = $e->{column} or die "no column";
- $items->[$i]->{$column} = $e->{new};
- warn "# commit $i $column ",dump( $e->{new} );
- $invalidate_columns->{$column}++;
+ if ( _hash_eq( $e->{old}, $items->[$i]->{$e->{column}} ) ) {
+ $status = 'found';
+ if ( $commit ) {
+ my $column = $e->{column} or die "no column";
+ $items->[$i]->{$column} = $e->{new};
+ warn "# commit $i $column ",dump( $e->{new} );
+ $invalidate_columns->{$column}++;
+ }
+ } else {
+ $status = 'source-changed';
}
}
- $e->{_status} = $status;
- $stats->{$status}++;
} elsif ( my $code = $e->{code} ) {
if ( $commit ) {
my $commit_changed;
MojoFacets::Data::__invalidate_path_column( $on_path, $_ ) foreach keys %$commit_changed;
MojoFacets::Data::__path_rebuild_stats( $on_path );
}
- $stats->{code}++;
+ $status = 'code';
+ if ( ( $apply || $commit ) && $e->{commit_changed} ) {
+ $status = 'found';
+ foreach my $c ( keys %{ $e->{commit_changed} } ) {
+ $status = 'missing' unless defined $MojoFacets::Data::loaded->{$path}->{stats}->{$c};
+ }
+ }
} else {
- warn "no unique in ", dump($e);
- $stats->{no_unique}++;
+ $status = 'unknown';
}
+
+ $e->{_status} = $status;
+ $stats->{$status}++;
+
push @$changes, $e;
}
+
foreach my $name ( keys %$invalidate_columns ) {
MojoFacets::Data::__invalidate_path_column( $on_path, $name );
}
unlink $self->_changes_path . '/' . $t;
}
- $self->redirect_to('/changes');
+ return $self->redirect_to('/changes');
}
1;