From 181198d07763f388a48c890ab297205b1eb3ef4d Mon Sep 17 00:00:00 2001 From: mkuba50 Date: Sun, 8 Oct 2017 17:10:00 +0200 Subject: [PATCH] Add fileinfo database caching --- listid.php | 39 ++++++++++++++++++++++++++++++++------- shared/main.php | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/listid.php b/listid.php index ba2e94a..daba862 100644 --- a/listid.php +++ b/listid.php @@ -26,18 +26,39 @@ function uupListIds() { $files = preg_grep('/\.json$/', $files); consoleLogger('Parsing database info...'); + + $database = @file_get_contents('cache/fileinfo.json'); + $database = json_decode($database, true); + if(empty($database)) $database = array(); + + $newDb = array(); $builds = array(); foreach($files as $file) { if($file == '.' || $file == '..') continue; - - $info = @file_get_contents('fileinfo/'.$file); - $info = json_decode($info, true); - $uuid = preg_replace('/\.json$/', '', $file); - $title = isset($info['title']) ? $info['title'] : 'UNKNOWN'; - $build = isset($info['build']) ? $info['build'] : 'UNKNOWN'; - $arch = isset($info['arch']) ? $info['arch'] : 'UNKNOWN'; + if(!isset($database[$uuid])) { + $info = @file_get_contents('fileinfo/'.$file); + $info = json_decode($info, true); + + $title = isset($info['title']) ? $info['title'] : 'UNKNOWN'; + $build = isset($info['build']) ? $info['build'] : 'UNKNOWN'; + $arch = isset($info['arch']) ? $info['arch'] : 'UNKNOWN'; + + $temp = array( + 'title' => $title, + 'build' => $build, + 'arch' => $arch, + ); + + $newDb = array_merge($newDb, array($uuid => $temp)); + } else { + $title = $database[$uuid]['title']; + $build = $database[$uuid]['build']; + $arch = $database[$uuid]['arch']; + + $newDb = array_merge($newDb, array($uuid => $database[$uuid])); + } $temp = array( 'title' => $title, @@ -60,6 +81,10 @@ function uupListIds() { consoleLogger('Done parsing database info.'); + if(!file_exists('cache')) mkdir('cache'); + $success = @file_put_contents('cache/fileinfo.json', json_encode($newDb)."\n"); + if(!$success) consoleLogger('Failed to update database cache.'); + return array( 'apiVersion' => uupApiVersion(), 'builds' => $builds, diff --git a/shared/main.php b/shared/main.php index dfdb01b..c8279f7 100644 --- a/shared/main.php +++ b/shared/main.php @@ -16,7 +16,7 @@ limitations under the License. */ function uupApiVersion() { - return '1.0.0'; + return '1.1.0'; } function uupApiPrintBrand() {