@@ -279,22 +279,54 @@ sub insert_result {
279
279
return 1;
280
280
}
281
281
}
282
+ if (!defined ($options {hs_sth })) {
283
+ $self -> {db_centreon }-> commit();
284
+ return 0;
285
+ }
282
286
283
287
# In Oracle 11: IGNORE_ROW_ON_DUPKEY_INDEX
284
288
# MS SQL: IGNORE_DUP_KEY
285
289
# Postgres: ???
286
- ($status , $sth ) = $self -> {db_centreon }-> query(' INSERT IGNORE INTO cfg_acl_resources_cache VALUES (' . $self -> {organization_id } . ' , ' . $options {acl_resource_id } . ' , ?, ?)' , prepare_only => 1);
290
+ my $prepare_str = ' (' . $self -> {organization_id } . ' , ' . $options {acl_resource_id } . ' , ?, ?)' ;
291
+ for (my $i = 1; $i < $self -> {config }{sql_bulk }; $i ++) {
292
+ $prepare_str .= ' , (' . $self -> {organization_id } . ' , ' . $options {acl_resource_id } . ' , ?, ?)' ;
293
+ }
294
+ ($status , $sth ) = $self -> {db_centreon }-> query(' INSERT IGNORE INTO cfg_acl_resources_cache VALUES ' . $prepare_str , prepare_only => 1);
287
295
my $rows = [];
288
296
my %host_insert = ();
289
297
my $i = 0;
298
+ my @array_binds = ();
290
299
while (my $row = ( shift (@$rows ) || # get row from cache, or reload cache:
291
300
shift (@{$rows = $options {hs_sth }-> fetchall_arrayref(undef , $self -> {config }{sql_fetch })||[]})) ) {
292
- $i ++;
301
+
293
302
if (!defined ($host_insert {$$row [0]})) {
294
303
$host_insert {$$row [0]} = 1;
295
- return 1 if ($self -> insert_execute(sth => $sth , bind => [1, $$row [0]]));
304
+ push @array_binds , 1, $$row [0];
305
+ $i ++;
306
+ if ($i == $self -> {config }{sql_bulk }) {
307
+ return 1 if ($self -> insert_execute(sth => $sth , bind => \@array_binds ));
308
+ $i = 0;
309
+ @array_binds = ();
310
+ }
296
311
}
297
- return 1 if ($self -> insert_execute(sth => $sth , bind => [2, $$row [1]]));
312
+
313
+ push @array_binds , 2, $$row [1];
314
+ $i ++;
315
+ if ($i == $self -> {config }{sql_bulk }) {
316
+ return 1 if ($self -> insert_execute(sth => $sth , bind => \@array_binds ));
317
+ $i = 0;
318
+ @array_binds = ();
319
+ }
320
+ }
321
+
322
+ if (scalar (@array_binds ) > 0) {
323
+ my $query = ' INSERT IGNORE INTO cfg_acl_resources_cache VALUES (' . $self -> {organization_id } . ' , ' . $options {acl_resource_id } . ' , ?, ?)' ;
324
+ my $num = scalar (@array_binds ) / 2;
325
+ for (my $i = 1; $i < $num ; $i ++) {
326
+ $query .= ' , (' . $self -> {organization_id } . ' , ' . $options {acl_resource_id } . ' , ?, ?)' ;
327
+ }
328
+ ($status , $sth ) = $self -> {db_centreon }-> query($query , prepare_only => 1);
329
+ return 1 if ($self -> insert_execute(sth => $sth , bind => \@array_binds ));
298
330
}
299
331
300
332
$self -> {db_centreon }-> commit();
@@ -318,11 +350,6 @@ sub action_aclresync {
318
350
return 1;
319
351
}
320
352
321
- if ($status == 2) {
322
- $self -> {logger }-> writeLogDebug(" centreondacl: organization $self ->{organization_id} acl resource $acl_resource_id : finished resync (emtpy resource)" );
323
- next ;
324
- }
325
-
326
353
$status = $self -> insert_result(acl_resource_id => $acl_resource_id , hs_sth => $sth , first_request => " DELETE FROM cfg_acl_resources_cache WHERE organization_id = '" . $self -> {organization_id } . " ' AND acl_resource_id = " . $acl_resource_id );
327
354
$self -> {logger }-> writeLogDebug(" centreondacl: organization $self ->{organization_id} acl resource $acl_resource_id : finished resync (status: $status )" );
328
355
if ($status == 1) {
@@ -400,15 +427,15 @@ sub run {
400
427
while (1) {
401
428
# we try to do all we can
402
429
my $rev = zmq_poll($self -> {poll }, 5000);
403
- if ($rev == 0 && $self -> {stop } == 1) {
430
+ if (defined ( $rev ) && $rev == 0 && $self -> {stop } == 1) {
404
431
$self -> {logger }-> writeLogInfo(" centreond-acl $$ has quit" );
405
432
zmq_close($socket );
406
433
exit (0);
407
434
}
408
435
409
436
# Check if we need to quit
410
437
if ($on_demand == 1) {
411
- if ($rev == 0) {
438
+ if (defined ( $rev ) && $rev == 0) {
412
439
if (time () - $on_demand_time > $self -> {config }{on_demand_time }) {
413
440
$self -> {logger }-> writeLogInfo(" centreond-acl $$ has quit" );
414
441
zmq_close($socket );
0 commit comments