From e3a5a6a170e63e3196793cab56b65332b06e8aab Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 22 Sep 2018 15:35:08 +0200 Subject: [PATCH] [index] Update and improve parameter handling for bridge and cache - Use 'array_diff_key' instead of 'unset' - Remove parameters for caches By removing certain parameters for caches, the loading times can be improved considerably: * action: It doesn't matter which action the user took to generate feed items. * format: This has the biggest impact on performance, because cached items are now shared between different formats (i.e. try switching between Atom, Html and Mrss and compare previous vs. now). If a server handles lots of requests, this may even reduce bandwidth if the same contents are requested for different formats. * _noproxy: The proxy behavior has no impact on the produced items, so it can be ignored. * _cache_timeout: This is another option which might impact performance for some servers, especially if 'custom_timeout' has been enabled in the configuration. Requests with different cache timeouts no longer result in separate cache files. --- index.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index a5a1786a..0bab8a0a 100644 --- a/index.php +++ b/index.php @@ -188,24 +188,43 @@ try { $cache_timeout = filter_var($params['_cache_timeout'], FILTER_VALIDATE_INT); } + // Remove parameters that don't concern bridges + $bridge_params = array_diff_key( + $params, + array_fill_keys( + array( + 'action', + 'bridge', + 'format', + '_noproxy', + '_cache_timeout', + ), '') + ); + + // Remove parameters that don't concern caches + $cache_params = array_diff_key( + $params, + array_fill_keys( + array( + 'action', + 'format', + '_noproxy', + '_cache_timeout', + ), '') + ); + // Initialize cache $cache = Cache::create('FileCache'); $cache->setPath(CACHE_DIR); $cache->purgeCache(86400); // 24 hours - $cache->setParameters($params); - - unset($params['action']); - unset($params['bridge']); - unset($params['format']); - unset($params['_noproxy']); - unset($params['_cache_timeout']); + $cache->setParameters($cache_params); // Load cache & data try { $bridge->setCache($cache); $bridge->setCacheTimeout($cache_timeout); $bridge->dieIfNotModified(); - $bridge->setDatas($params); + $bridge->setDatas($bridge_params); } catch(Error $e) { http_response_code($e->getCode()); header('Content-Type: text/html');