console.time('Создание элементов')
var elem=document.createElement('div');
elem.innerHTML=createBigCode()
console.timeEnd('Создание элементов')
console.time('Поиск элементов')
var elems =elem.querySelectorAll('li');
var Elems=findSame(elems,'data-item');
console.timeEnd('Поиск элементов')
console.log(Elems)
function findSame(elems,attr){
var Elems={};
for(var i=0;i<elems.length;i++){
var elem=elems[i];
var key =elem.getAttribute(attr);
Elems[key]=Array.isArray(Elems[key])?Elems[key]:[];
Elems[key].push(elem);
}
return Elems;
}
function createBigCode(){
var steps=100000;
var html='';
function ramdom(i){
i=i||10;
return Math.ceil(Math.random()*i);
}
for(var i=0;i<steps;i++){
var ram=ramdom(steps/100);
var fragment="<li data-item='srt-"+ram+"'>Супер коммент со значением "+ram+"</li>";
html+=fragment;
}
return html;
}
@MaxLevs: function findNotLincImages(){
$conect=$this->connectToDb();
$post=$_POST;
$removed=0;
if(!$post['dir'])return ["error"=>true,"error_msg"=>"Папка не определена"];
$dir=$this->image_dir[$post['dir']];
$files=scandir($dir);
if(!$files)return ["error"=>true,"error_msg"=>"Ошибка каталога"];
$sql="INSERT IGNORE INTO cache_image_dir (`name`) VALUES ('";
$names=[];
foreach ($files as $name){
preg_match("/\.(jpg|png)/", $name, $match);
if(!$match[0])continue;
array_push($names,$name);
}
$sql.= join("'),('",$names)."');";
$conect->query($sql);
if($conect->error){
return ["error"=>true,"error_msg"=>"Ошибка обновления данных"];
}
$sql='select name from cache_image_dir where name not in( select name from category_image);';
if ($result = mysqli_query($conect, $sql)) {
while($row = $result->fetch_array(MYSQL_ASSOC)) {
$name=$row['name'];
$removed++;
$this->removeImageFile($dir,$name);
}
}
$sql='delete from cache_image_dir';
$conect->query($sql);
return ["success"=>true,"removed"=>$removed];
}
ordered_products.`count`=ordered_products.`count`+$product[count];";