1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

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.
This commit is contained in:
Raymond Hill 2019-10-15 11:42:43 -04:00
parent 5a85ff9a93
commit 0f19dfde38
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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);
}