diff --git a/fetchupd.php b/fetchupd.php index c0a2c28..8656caf 100644 --- a/fetchupd.php +++ b/fetchupd.php @@ -353,6 +353,7 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku if($success) { consoleLogger('Successfully written build information to the disk.'); $fileWrite = 'INFO_WRITTEN'; + uupApiPrivateInvalidateFileinfoCache(); } else { consoleLogger('An error has occured while writing the information to the disk.'); } diff --git a/listid.php b/listid.php index 38d3bed..7d11f88 100644 --- a/listid.php +++ b/listid.php @@ -16,11 +16,18 @@ limitations under the License. */ require_once dirname(__FILE__).'/shared/main.php'; +require_once dirname(__FILE__).'/shared/cache.php'; -function uupListIds($search = null, $sortByDate = 0) { - uupApiPrintBrand(); +function uupApiPrivateInvalidateFileinfoCache() { + $cache1 = new UupDumpCache('listid-0', false); + $cache2 = new UupDumpCache('listid-1', false); - if(!file_exists('fileinfo')) return array('error' => 'NO_FILEINFO_DIR'); + $cache1->delete(); + $cache2->delete(); +} + +function uupApiPrivateGetFromFileinfo($sortByDate = 0) { + if(!file_exists('fileinfo')) return false; $files = scandir('fileinfo'); $files = preg_grep('/\.json$/', $files); @@ -105,12 +112,7 @@ function uupListIds($search = null, $sortByDate = 0) { $builds[$tmp.$arch.$title.$uuid] = $temp; } - if(empty($buildAssoc)) { - return array( - 'apiVersion' => uupApiVersion(), - 'builds' => array(), - ); - } + if(empty($buildAssoc)) return []; krsort($buildAssoc); $buildsNew = array(); @@ -141,6 +143,26 @@ function uupListIds($search = null, $sortByDate = 0) { if(!$success) consoleLogger('Failed to update database cache.'); } + return $builds; +} + +function uupListIds($search = null, $sortByDate = 0) { + uupApiPrintBrand(); + + $sortByDate = $sortByDate ? 1 : 0; + + $res = "listid-$sortByDate"; + $cache = new UupDumpCache($res, false); + $builds = $cache->get(); + $cached = ($builds !== false); + + if(!$cached) { + $builds = uupApiPrivateGetFromFileinfo($sortByDate); + if($builds === false) return ['error' => 'NO_FILEINFO_DIR']; + + $cache->put($builds, 60); + } + if($search) { if(!preg_match('/^regex:/', $search)) { $searchSafe = preg_quote($search, '/'); diff --git a/shared/main.php b/shared/main.php index c2ad13e..c9972cf 100644 --- a/shared/main.php +++ b/shared/main.php @@ -16,7 +16,7 @@ limitations under the License. */ function uupApiVersion() { - return '1.33.0'; + return '1.34.0-dev'; } require_once dirname(__FILE__).'/auths.php';