From 5419c1e76a18a41c50b3bc30e41325e1a0666cf5 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Thu, 8 Jul 2021 17:52:05 +0300 Subject: [PATCH] Bug 28692 - log without indentation to decrease DB action_log table size Indentation symbols like spaces and newlines take up a large amount of extra space. Example: fully indented action_log item MODIFY record weighs from 1.6 to 370 KB while the version of it without any indentation takes 1.1 to 46 KB accordingly. This patch adds Indent(0) parameter of Data::Dumper to output without indentation. To reproduce for item: 1) edit any item you see fit, save it. 2) check the action_logs table and find there a newly created MODIFY item row, "info" column of that contains dumped data, see that it has indentation, optional: check and note about the size of it. 3) apply the patch. 4) edit that item again and save it afterwards. 5) "info" column of the newly created row should contain non-indented text now. If you did check the size of the previous dump, compare it with this new one, check the difference it makes. To reproduce for hold: 1) in syspref set HoldsLog to Log. 1) go to the biblio page and suspend and resume any hold you see fit. 2) check the action_logs table and find there a newly created SUSPEND item row, "info" column of that contains dumped data, see that it has indentation, optional: check and note about the size of it. 3) apply the patch. 4) edit that item again and save it afterwards. 5) "info" column of the newly created row should contain non-indented text now. If you did check the size of the previous dump, compare it with this new one, check the difference it makes. --- C4/Reserves.pm | 9 ++++----- Koha/Hold.pm | 8 ++++---- Koha/Item.pm | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 83222dc1c5..ae4f48f5b8 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -257,7 +257,7 @@ sub AddReserve { )->store(); $hold->set_waiting() if $found && $found eq 'W'; - logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) ) + logaction( 'HOLDS', 'CREATE', $hold->id, Data::Dumper->new([$hold->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); my $reserve_id = $hold->id(); @@ -1046,7 +1046,7 @@ sub ModReserve { $hold->cancel({ cancellation_reason => $cancellation_reason }); } elsif ($rank =~ /^\d+/ and $rank > 0) { - logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) + logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Data::Dumper->new([$hold->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); my $properties = { @@ -1107,8 +1107,7 @@ sub ModReserveFill { priority => 0, } ); - - logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) + logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Data::Dumper->new([$hold->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log @@ -1236,7 +1235,7 @@ sub ModReserveAffect { }); $std->execute($hold->reserve_id); - logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->get_from_storage->unblessed) ) + logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Data::Dumper->new([$hold->get_from_storage->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); return; diff --git a/Koha/Hold.pm b/Koha/Hold.pm index bd5458f494..6912ac25ce 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -114,7 +114,7 @@ sub suspend_hold { $self->suspend_until($date); $self->store(); - logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, Dumper( $self->unblessed ) ) + logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, Data::Dumper->new([$self->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); return $self; @@ -134,7 +134,7 @@ sub resume { $self->store(); - logaction( 'HOLDS', 'RESUME', $self->reserve_id, Dumper($self->unblessed) ) + logaction( 'HOLDS', 'RESUME', $self->reserve_id, Data::Dumper->new([$self->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); return $self; @@ -151,7 +151,7 @@ sub delete { my $deleted = $self->SUPER::delete($self); - logaction( 'HOLDS', 'DELETE', $self->reserve_id, Dumper($self->unblessed) ) + logaction( 'HOLDS', 'DELETE', $self->reserve_id, Data::Dumper->new([$self->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); return $deleted; @@ -569,7 +569,7 @@ sub cancel { ); } - C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, Dumper($self->unblessed) ) + C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, Data::Dumper->new([$self->unblessed], [qw(hold)])->Indent(0)->Sortkeys(1)->Dump ) if C4::Context->preference('HoldsLog'); } ); diff --git a/Koha/Item.pm b/Koha/Item.pm index 47a86eb0bb..c2a6ecb80b 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -203,7 +203,7 @@ sub store { if ( $log_action && C4::Context->preference("CataloguingLog") ) { $action eq 'create' ? logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" ) - : logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Dumper( $self->unblessed ) ); + : logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Data::Dumper->new([$self->unblessed], [qw(item)])->Indent(0)->Sortkeys(1)->Dump ); } my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ) -- 2.31.1