/* v150300: Kategori + marka hızlı ürün indeksi. * Dinamik sayfalar eski HTML cache'inden verilmez. Bunun yerine ürün snapshot'ındaki * pozisyonlar kategori yolu ve marka anahtarına göre küçük bir PHP indeksinde tutulur. */ function fa_products_filter_index_file(){ return fa_runtime_cache_dir() . '/products_filter_index_latest.php'; } function fa_products_filter_index_path_key($parts){ $out=[]; foreach ((array)$parts as $part){ $slug=fa_slug(trim((string)$part)); if($slug!=='') $out[]=$slug; } return implode('/', $out); } function fa_build_products_filter_index($products=null, $force=false){ $file=fa_products_filter_index_file(); $lockFile=fa_runtime_cache_dir().'/products_filter_index_latest.lock'; $lock=@fopen($lockFile,'c'); if(!$lock) return false; if(!@flock($lock, LOCK_EX|LOCK_NB)){@fclose($lock);return false;} $source=fa_data_file_path('products.json'); $sourceMtime=is_file($source)?(int)@filemtime($source):0; if(!$force && is_file($file)){ $cur=@include $file; if(is_array($cur) && (int)($cur['source_mtime']??0)>=$sourceMtime){ @flock($lock,LOCK_UN);@fclose($lock);return true; } } if(!is_array($products)) $products=fa_products_public_fast(true); $paths=[];$pathBrands=[];$brands=[]; foreach($products as $i=>$p){ if(!is_array($p)) continue; $parts=fa_product_category_path_parts_fast($p); $brandSlug=fa_slug((string)($p['brand']??'')); if($brandSlug!=='') $brands[$brandSlug][]=$i; $prefix=[]; foreach($parts as $part){ $slug=fa_slug((string)$part); if($slug==='') continue; $prefix[]=$slug; $key=implode('/',$prefix); $paths[$key][]=$i; if($brandSlug!=='') $pathBrands[$key.'|'.$brandSlug][]=$i; } } $payload=['source_mtime'=>$sourceMtime,'product_count'=>count($products),'built_at'=>time(),'paths'=>$paths,'path_brands'=>$pathBrands,'brands'=>$brands]; $ok=fa_atomic_php_cache_write($file,$payload); @flock($lock,LOCK_UN);@fclose($lock); return $ok; } function fa_products_filter_index_load($products){ $file=fa_products_filter_index_file(); $source=fa_data_file_path('products.json'); $sourceMtime=is_file($source)?(int)@filemtime($source):0; $idx=is_file($file)?@include $file:null; $valid=is_array($idx) && isset($idx['paths'],$idx['path_brands'],$idx['brands']) && (int)($idx['product_count']??-1)===count((array)$products) && (int)($idx['source_mtime']??0)>=$sourceMtime; if(!$valid){ fa_build_products_filter_index($products,true); clearstatcache(true,$file); $idx=is_file($file)?@include $file:null; } return is_array($idx)?$idx:[]; } function fa_products_filter_index_subset($products,$pathParts=[],$brand=''){ if(!is_array($products)||!$products) return []; $pathKey=fa_products_filter_index_path_key($pathParts); $brandKey=fa_slug((string)$brand); if($pathKey==='' && $brandKey==='') return $products; $idx=fa_products_filter_index_load($products); $positions=null; if($pathKey!=='' && $brandKey!=='') $positions=$idx['path_brands'][$pathKey.'|'.$brandKey]??[]; elseif($pathKey!=='') $positions=$idx['paths'][$pathKey]??[]; else $positions=$idx['brands'][$brandKey]??[]; if(!is_array($positions)) return $products; $out=[]; foreach($positions as $pos){ $pos=(int)$pos; if(isset($products[$pos])&&is_array($products[$pos])) $out[]=$products[$pos]; } return $out; } U.S. Polo Assn. Kadın Koyu Yeşil Hırka (Örme) 50316729-VR079 İndirimi | Fırsat Avcıları
25 / 12191 ürün gösteriliyor
Ana Sayfa