From 0f19dfde3887233674c5cc07413cb743a2a94319 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 15 Oct 2019 11:42:43 -0400 Subject: [PATCH] Avoid or defer writing back to cache storage at launch The readTime property is unused for compiled or selfie assets, and thus writing back to storage to persist this property is useless for those assets, and an undue overhead when reading such assets, especially at launch time. Assets are always loaded from their compiled or selfie counterparts at launch. This commit will prevent those unnecessary storage write operations. --- src/js/assets.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/js/assets.js b/src/js/assets.js index 4df705992..899af85de 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -475,19 +475,19 @@ const saveAssetCacheRegistry = (( ) => { return function(lazily) { if ( timer !== undefined ) { clearTimeout(timer); } if ( lazily ) { - timer = vAPI.setTimeout(save, 500); + timer = vAPI.setTimeout(save, 30000); } else { save(); } }; })(); -const assetCacheRead = async function(assetKey) { +const assetCacheRead = async function(assetKey, updateReadTime = false) { const internalKey = `cache/${assetKey}`; const reportBack = function(content) { if ( content instanceof Blob ) { content = ''; } - let details = { assetKey: assetKey, content: content }; + const details = { assetKey: assetKey, content: content }; if ( content === '' ) { details.error = 'ENOTFOUND'; } return details; }; @@ -509,7 +509,10 @@ const assetCacheRead = async function(assetKey) { } entry.readTime = Date.now(); - saveAssetCacheRegistry(true); + if ( updateReadTime ) { + saveAssetCacheRegistry(true); + } + return reportBack(bin[internalKey]); }; @@ -676,7 +679,12 @@ api.get = async function(assetKey, options = {}) { return details; }; - const details = await assetCacheRead(assetKey); + // Skip read-time property for non-updatable assets: the property is + // completely unused for such assets and thus there is no point incurring + // storage write overhead at launch when reading compiled or selfie assets. + const updateReadTime = /^(?:compiled|selfie)\//.test(assetKey) === false; + + const details = await assetCacheRead(assetKey, updateReadTime); if ( details.content !== '' ) { return reportBack(details.content); }