From dba09016d6ed0480151bfa4ad0310e7b87c3ccd3 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Mon, 12 Jul 2021 16:58:20 +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 changes logaction subroutine to perform a special transformation, if$info came as known object, that 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/Log.pm | 11 +++++++++++ C4/Reserves.pm | 8 ++++---- Koha/Hold.pm | 8 ++++---- Koha/Item.pm | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/C4/Log.pm b/C4/Log.pm index 5a9077de0d..01a14df268 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -68,6 +68,17 @@ number is set to 0, which is the same as the superlibrarian's number. sub logaction { my ($modulename, $actionname, $objectnumber, $infos, $interface)=@_; + # Do special transformations if $info came as below-known object: + my $varname; + if ( ref $infos eq 'Koha::Hold' ) { + $varname = 'hold'; + } elsif ( ref $infos eq 'Koha::Item' ) { + $varname = 'item'; + } + if ($varname) { + $infos = Data::Dumper->new( [ $infos->unblessed ], [$varname] )->Indent(0)->Sortkeys(1)->Dump; + } + # Get ID of logged in user. if called from a batch job, # no user session exists and C4::Context->userenv() returns # the scalar '0'. diff --git a/C4/Reserves.pm b/C4/Reserves.pm index f2ee463979..baba494ba4 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -261,7 +261,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, $hold ) if C4::Context->preference('HoldsLog'); my $reserve_id = $hold->id(); @@ -1060,7 +1060,7 @@ sub ModReserve { $hold->expirationdate(dt_from_string($date))->store(); } elsif ($rank =~ /^\d+/ and $rank > 0) { - logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) + logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold ) if C4::Context->preference('HoldsLog'); my $properties = { @@ -1122,7 +1122,7 @@ sub ModReserveFill { } ); - logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) + logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold ) if C4::Context->preference('HoldsLog'); # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log @@ -1250,7 +1250,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, $hold->get_from_storage ) if C4::Context->preference('HoldsLog'); return; diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 26c41d7924..76c81dbabd 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -113,7 +113,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, $self ) if C4::Context->preference('HoldsLog'); return $self; @@ -133,7 +133,7 @@ sub resume { $self->store(); - logaction( 'HOLDS', 'RESUME', $self->reserve_id, Dumper($self->unblessed) ) + logaction( 'HOLDS', 'RESUME', $self->reserve_id, $self ) if C4::Context->preference('HoldsLog'); return $self; @@ -150,7 +150,7 @@ sub delete { my $deleted = $self->SUPER::delete($self); - logaction( 'HOLDS', 'DELETE', $self->reserve_id, Dumper($self->unblessed) ) + logaction( 'HOLDS', 'DELETE', $self->reserve_id, $self ) if C4::Context->preference('HoldsLog'); return $deleted; @@ -568,7 +568,7 @@ sub cancel { ); } - C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, Dumper($self->unblessed) ) + C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, $self ) if C4::Context->preference('HoldsLog'); } ); diff --git a/Koha/Item.pm b/Koha/Item.pm index 60d80a5c3e..9544bbaf33 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -202,7 +202,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, $self ); } my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ) -- 2.31.1