mirror of https://github.com/MISP/MISP
chg: [internal] Faster checking if array is list
parent
87a94a9345
commit
dff9a5eca2
|
@ -633,7 +633,7 @@ class RestResponseComponent extends Component
|
|||
}
|
||||
|
||||
// If response is big array, encode items separately to save memory
|
||||
if (is_array($response) && count($response) > 10000) {
|
||||
if (is_array($response) && count($response) > 10000 && JsonTool::arrayIsList($response)) {
|
||||
$output = new TmpFileTool();
|
||||
$output->write('[');
|
||||
|
||||
|
|
|
@ -68,6 +68,27 @@ class JsonTool
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://www.php.net/manual/en/function.array-is-list.php
|
||||
* @param array $array
|
||||
* @return bool
|
||||
*/
|
||||
public static function arrayIsList(array $array)
|
||||
{
|
||||
if (function_exists('array_is_list')) {
|
||||
return array_is_list($array);
|
||||
}
|
||||
|
||||
$i = -1;
|
||||
foreach ($array as $k => $v) {
|
||||
++$i;
|
||||
if ($k !== $i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON supports just unicode strings. This helper method converts non unicode chars to Unicode Replacement Character U+FFFD (UTF-8)
|
||||
* @param string $string
|
||||
|
|
|
@ -390,8 +390,7 @@ class Warninglist extends AppModel
|
|||
$warninglistId = (int)$this->id;
|
||||
$result = true;
|
||||
|
||||
$keys = array_keys($list['list']);
|
||||
if ($keys === array_keys($keys)) {
|
||||
if (JsonTool::arrayIsList($list['list'])) {
|
||||
foreach (array_chunk($list['list'], 1000) as $chunk) {
|
||||
$valuesToInsert = [];
|
||||
foreach ($chunk as $value) {
|
||||
|
|
Loading…
Reference in New Issue