fix: [server caching] only push data to redis / logs if there's something to push

- avoids the count() notice if no data was returned by the remote
pull/7525/head
iglocska 2021-06-21 08:44:11 +02:00
parent 0311b43e08
commit 3d794b62a9
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 5 additions and 5 deletions

View File

@ -4190,12 +4190,12 @@ class Server extends AppModel
$HttpSocket = $this->setupHttpSocket($server, $HttpSocket);
while ($continue) {
$i++;
$pipe = $redis->multi(Redis::PIPELINE);
$chunk_size = 50000;
$data = $this->__getCachedAttributes($server, $HttpSocket, $chunk_size, $i);
if (empty(trim($data))) {
$continue = false;
} else {
$pipe = $redis->multi(Redis::PIPELINE);
$data = explode(PHP_EOL, trim($data));
foreach ($data as $entry) {
list($value, $uuid) = explode(',', $entry);
@ -4209,11 +4209,11 @@ class Server extends AppModel
$redis->sAdd('misp:server_cache:event_uuid_lookup:' . $value, $server['Server']['id'] . '/' . $uuid);
}
}
$pipe->exec();
if ($jobId) {
$job->saveField('message', 'Server ' . $server['Server']['id'] . ': ' . ((($i -1) * $chunk_size) + count($data)) . ' attributes cached.');
}
}
if ($jobId) {
$job->saveField('message', 'Server ' . $server['Server']['id'] . ': ' . ((($i -1) * $chunk_size) + count($data)) . ' attributes cached.');
}
$pipe->exec();
}
$redis->set('misp:server_cache_timestamp:' . $server['Server']['id'], time());
return true;