up without batch

This commit is contained in:
Tykayn 2025-06-05 16:20:20 +02:00 committed by tykayn
parent 4c1a7729a1
commit 409bff6d4c
4 changed files with 86 additions and 201 deletions

View file

@ -12,7 +12,7 @@ class Motocultrice
public $overpass_base_places = '
(
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall|animal_boarding|animal_breeding|animal_shelter|animal_training|archive|arts_centre|bank|bar|bicycle_rental|biergarten|boat_rental|boat_storage|bureau_de_change|cafe|canteen|car_rental|car_wash|casino|childcare|clinic|college|conference_centre|courthouse|coworking_space|crematorium|dancing_school|dentist|dive_centre|doctors|dojo|driver_training|driving_school|events_venue|financial_advice|fire_station|flight_school|food_court|fuel|funeral_hall|hookah_lounge|hospital|ice_cream|internet_cafe|karaoke_box|kindergarten|language_school|love_hotel|medical_supply|monastery|money_transfer|motorcycle_rental|music_school|music_venue|nightclub|nursing_home|pharmacy|place_of_mourning|place_of_worship|police|post_depot|prep_school|prison|pub|public_bath|ranger_station|research_institute|sailing_school|school|ski_rental|ski_school|social_centre|social_facility|stripclub|student_accommodation|studio|surf_school|swingerclub|theatre|toy_library|university|vehicle_inspection|veterinary|waste_transfer_station|workshop|art_school|atm|bar||bicycle_parking|bicycle_repair_station|boat_school|bus_station|clock|clubhouse|coffee|construction_equipment_rental|cooking_school|deposit_sale|dog_toilet|drive_school|estate_agent|event|fixme|florist|groundskeeping|group_home|health_facility|healthcare|hearing_aid|hearing_aids|herbalist|laboratory|office|parcel_locker|personal_service|photo_booth|printer|professional_school|public_building|public_service|recycling|scuba_diving_school|septic_tank|software_engineering|spa|swingerclub for swinger clubs|taxi|teahouse|toilets|training|underprivileged|vehicule_inspection|vending_machine|warehouse)$"](area.searchArea);
nw["amenity"~"^(cafe|bar|restaurant|library|cinema|fast_food|post_office|marketplace|community_centre|theatre|bank|townhall|animal_boarding|animal_breeding|animal_shelter|animal_training|archive|arts_centre|bank|bar|bicycle_rental|biergarten|boat_rental|boat_storage|bureau_de_change|cafe|canteen|car_rental|car_wash|casino|childcare|clinic|college|conference_centre|courthouse|coworking_space|crematorium|dancing_school|dentist|dive_centre|doctors)$"](area.searchArea);
nw["shop"](area.searchArea);
nw["healthcare"](area.searchArea);
nw["office"](area.searchArea);
@ -155,42 +155,33 @@ out center tags;';
public function labourer(string $zone): array
{
try {
$query = $this->get_query_places($zone);
$response = $this->client->request('POST', $this->overpassApiUrl, [
'body' => ['data' => $this->get_query_places($zone)]
'body' => ['data' => $query]
]);
$data = json_decode($response->getContent(), true);
$places = [];
if (isset($data['elements'])) {
$batchSize = 100; // Traiter par lots de 100 éléments
$totalElements = count($data['elements']);
for ($i = 0; $i < $totalElements; $i += $batchSize) {
$batch = array_slice($data['elements'], $i, $batchSize);
foreach ($batch as $element) {
if (isset($element['tags'])) {
$email = "";
$places[] = [
'id' => $element['id'],
'type' => $element['type'],
'name' => $element['tags']['name'] ?? '',
'email' => $email,
'lat' => $element['lat'] ?? null,
'lon' => $element['lon'] ?? null,
'tags' => $element['tags']
];
}
foreach ($data['elements'] as $element) {
if (isset($element['tags'])) {
$places[] = [
'id' => $element['id'],
'type' => $element['type'],
'name' => $element['tags']['name'] ?? '',
'lat' => $element['lat'] ?? null,
'lon' => $element['lon'] ?? null,
'tags' => $element['tags']
];
}
// Libérer la mémoire après chaque lot
unset($batch);
gc_collect_cycles();
}
}
// Libérer la mémoire
unset($data);
gc_collect_cycles();
return $places;
} catch (\Exception $e) {
throw new \Exception("Erreur lors de la requête Overpass : " . $e->getMessage());