set execution time and memory when refreshing the data

This commit is contained in:
Rev 2021-10-26 11:37:51 +09:00
parent a269395b9e
commit 33da8354db

View File

@ -3,6 +3,7 @@
namespace App\Data;
use App\Exceptions\ItemNotFoundException;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
@ -34,8 +35,16 @@ class ItemsCollection
}
}
/**
* @return void
* @throws Exception
*/
public function refreshLocalesCache(): void
{
$time_limit = ini_get('max_execution_time');
$memory_limit = ini_get('memory_limit');
set_time_limit(180);
ini_set('memory_limit', '256M');
$this->locales = [];
$rawLocalesGlobalBaseUrl = GiteaConfig::RAW_LOCALES_GLOBAL_BASE_URL;
@ -55,18 +64,35 @@ class ItemsCollection
$customizationLocale = $currentLocaleJson['customization'];
$this->locales[$trimmedCurrentLocaleName] = array_merge($templateLocale, $customizationLocale);
}
file_put_contents(storage_path($this->locales_file_key ), json_encode($this->locales));
if (!$handle = fopen(storage_path($this->locales_file_key ), 'w')) {
throw new Exception('Cannot open the file');
}
fwrite($handle, json_encode($this->locales));
fclose($handle);
set_time_limit($time_limit);
ini_set('memory_limit', $memory_limit);
}
/**
* @return void
* @throws Exception
*/
public function refreshItemsCache(): void
{
$time_limit = ini_get('max_execution_time');
$memory_limit = ini_get('memory_limit');
set_time_limit(180);
ini_set('memory_limit', '256M');
$items = Http::withOptions(['verify' => false])->get(GiteaConfig::RAW_ITEMS_URL)->json();
$customization = Http::withOptions(['verify' => false])->get(GiteaConfig::RAW_CUSTOMIZATION_URL)->json();
$this->items = array_merge($items, $customization);
file_put_contents(storage_path($this->items_file_key), json_encode($this->items));
if (!$handle = fopen(storage_path($this->items_file_key ), 'w')) {
throw new Exception('Cannot open the file');
}
fwrite($handle, json_encode($this->items));
fclose($handle);
set_time_limit($time_limit);
ini_set('memory_limit', $memory_limit);
}
/**
@ -79,6 +105,7 @@ class ItemsCollection
/**
* @return void
* @throws Exception
*/
public function refreshAllCache(): void
{