From 4971a19b8a6d309952d1b25cabbae323259919e5 Mon Sep 17 00:00:00 2001 From: eraseyourknees <112027564+eraseyourknees@users.noreply.github.com> Date: Fri, 26 Aug 2022 20:10:15 +0200 Subject: [PATCH 1/3] Add listid response caching --- fetchupd.php | 1 + listid.php | 40 +++++++++++++++++++++++++++++++--------- shared/main.php | 2 +- 3 files changed, 33 insertions(+), 10 deletions(-) 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'; From 2d5fcf1f15a81168e323111d0c7fe276fc70b605 Mon Sep 17 00:00:00 2001 From: eraseyourknees <112027564+eraseyourknees@users.noreply.github.com> Date: Sat, 27 Aug 2022 02:47:32 +0200 Subject: [PATCH 2/3] Fix 0 being interpreted as false --- listid.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listid.php b/listid.php index 7d11f88..c23f3b1 100644 --- a/listid.php +++ b/listid.php @@ -163,7 +163,7 @@ function uupListIds($search = null, $sortByDate = 0) { $cache->put($builds, 60); } - if($search) { + if($search != null) { if(!preg_match('/^regex:/', $search)) { $searchSafe = preg_quote($search, '/'); From 547aa1512a17f9104bae05735f79c6bb7649249e Mon Sep 17 00:00:00 2001 From: eraseyourknees <112027564+eraseyourknees@users.noreply.github.com> Date: Sun, 28 Aug 2022 14:49:18 +0200 Subject: [PATCH 3/3] 1.34.0 --- shared/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/main.php b/shared/main.php index c9972cf..242d7fb 100644 --- a/shared/main.php +++ b/shared/main.php @@ -16,7 +16,7 @@ limitations under the License. */ function uupApiVersion() { - return '1.34.0-dev'; + return '1.34.0'; } require_once dirname(__FILE__).'/auths.php';