correctly load multiple params for paths
[MojoFacets.git] / lib / MojoFacets / Changes.pm
index 8f3e344..ca22b4e 100644 (file)
@@ -15,6 +15,15 @@ sub _changes_path {
        $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');
@@ -26,8 +35,7 @@ sub index {
                $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";
        }
@@ -55,12 +63,16 @@ sub index {
                        }
                        $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';
                                }
                        }
                } elsif ( my $code = $e->{code} ) {
@@ -119,7 +131,7 @@ sub remove {
                unlink $self->_changes_path . '/' . $t;
        }
 
-       $self->redirect_to('/changes');
+       return $self->redirect_to('/changes');
 }
 
 1;