@@ -101,6 +101,44 @@ sub exit_process {
101101 exit (0);
102102}
103103
104+ # apply vacuum on the database every week
105+ sub action_dbvacuum {
106+ my ($self , %options ) = @_ ;
107+
108+ $options {token } = $self -> generate_token() if (!defined ($options {token }));
109+
110+ if (defined ($options {cycle })) {
111+ return 0 if ((time () - $self -> {purge_vacuum_timer }) < 3600*24*7); # doing vacuum every week as it can be slow on some database
112+ }
113+ $self -> {logger }-> writeLogDebug(" [dbcleaner] vacuum database in progress..." );
114+ my ($status ) = $self -> {db_gorgone }-> query({
115+ query => " VACUUM"
116+ });
117+ $self -> {purge_vacuum_timer } = time ();
118+
119+ $self -> {logger }-> writeLogDebug(" [dbcleaner] vacuum finished" );
120+
121+ if ($status == -1) {
122+ $self -> send_log(
123+ code => GORGONE_ACTION_FINISH_KO,
124+ token => $options {token },
125+ data => {
126+ message => ' action db vacuum failed'
127+ }
128+ );
129+ return 0;
130+ }
131+
132+ $self -> send_log(
133+ code => GORGONE_ACTION_FINISH_OK,
134+ token => $options {token },
135+ data => {
136+ message => ' action db vacuum finished'
137+ }
138+ );
139+ return 0;
140+ }
141+ # purge database
104142sub action_dbclean {
105143 my ($self , %options ) = @_ ;
106144
@@ -127,14 +165,12 @@ sub action_dbclean {
127165 query => " DELETE FROM gorgone_history WHERE (instant = 1 AND `ctime` < " . (time () - 86400) . " ) OR `ctime` < ?" ,
128166 bind_values => [time () - $self -> {config }-> {purge_history_time }]
129167 });
130- my ($status3 ) = $self -> {db_gorgone }-> query({
131- query => " VACUUM"
132- });
168+
133169 $self -> {purge_timer } = time ();
134170
135171 $self -> {logger }-> writeLogDebug(" [dbcleaner] Purge finished" );
136172
137- if ($status == -1 || $status2 == -1 || $status3 == -1 ) {
173+ if ($status == -1 || $status2 == -1) {
138174 $self -> send_log(
139175 code => GORGONE_ACTION_FINISH_KO,
140176 token => $options {token },
@@ -161,6 +197,7 @@ sub periodic_exec {
161197 }
162198
163199 $connector -> action_dbclean(cycle => 1);
200+ $connector -> action_dbvacuum(cycle => 1);
164201}
165202
166203sub run {
0 commit comments