Skip to content

Commit

Permalink
Remove "Purge all caches" button from "Filter lists" pane
Browse files Browse the repository at this point in the history
Purging all the lists from cache storage is detrimental to
differential update, and cause filter lists to be updated less
often and consequently to be less up to date then when letting
differential updater do its work.
  • Loading branch information
gorhill committed Dec 14, 2023
1 parent 1492691 commit bd7ce41
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 202 deletions.
1 change: 0 additions & 1 deletion src/3p-filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<div id="actions">
<button id="buttonApply" class="preferred disabled iconified" type="button" data-i18n-title="3pApplyChanges"><span class="fa-icon">check</span><span data-i18n="3pApplyChanges">_</span><span class="hover"></span></button>
<button id="buttonUpdate" class="preferred disabled iconified" type="button" data-i18n-title="3pUpdateNow"><span class="fa-icon">refresh</span><span data-i18n="3pUpdateNow">_</span><span class="hover"></span></button>
<button id="buttonPurgeAll" class="disabled iconified" type="button" data-i18n-title="3pPurgeAll"><span class="fa-icon">clock-o</span><span data-i18n="3pPurgeAll">_</span><span class="hover"></span></button>
</div>

<div>
Expand Down
1 change: 1 addition & 0 deletions src/devtools.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<button id="snfe-todnr" type="button">SNFE: DNR<span class="hover"></span></button>
<button id="snfe-benchmark" type="button" disabled>SNFE: Benchmark<span class="hover"></span></button>
<button id="cfe-dump" type="button">CFE: Dump<span class="hover"></span></button>
<button id="purge-all-caches" type="button" data-i18n-title="3pPurgeAll"><span data-i18n="3pPurgeAll">_</span><span class="hover"></span></button>
</div>
<div id="console" class="codeMirrorContainer"></div>

Expand Down
31 changes: 12 additions & 19 deletions src/js/3p-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const renderFilterLists = ( ) => {
renderWidgets();
};

vAPI.messaging.send('dashboard', {
return vAPI.messaging.send('dashboard', {
what: 'getLists',
}).then(response => {
onListsReceived(response);
Expand All @@ -295,9 +295,6 @@ const renderWidgets = ( ) => {
updating === false &&
qs$('#lists .listEntry.checked.obsolete:not(.toRemove)') === null
);
dom.cl.toggle('#buttonPurgeAll', 'disabled',
updating || qs$('#lists .listEntry.cached:not(.obsolete)') === null
);
};

/******************************************************************************/
Expand Down Expand Up @@ -510,15 +507,17 @@ const onPurgeClicked = ev => {
}

vAPI.messaging.send('dashboard', {
what: 'purgeCaches',
what: 'listsUpdateNow',
assetKeys,
preferOrigin: ev.shiftKey,
});

// If the cached version is purged, the installed version must be assumed
// to be obsolete.
// https://github.com/gorhill/uBlock/issues/1733
// An external filter list must not be marked as obsolete, they will
// always be fetched anyways if there is no cached copy.
dom.cl.add(dom.body, 'updating');
dom.cl.add(liEntry, 'obsolete');

if ( qs$(liEntry, 'input[type="checkbox"]').checked ) {
Expand Down Expand Up @@ -608,25 +607,13 @@ const buttonUpdateHandler = async ( ) => {
await selectFilterLists();
dom.cl.add(dom.body, 'updating');
renderWidgets();
vAPI.messaging.send('dashboard', { what: 'forceUpdateAssets' });
vAPI.messaging.send('dashboard', { what: 'updateNow' });
};

dom.on('#buttonUpdate', 'click', ( ) => { buttonUpdateHandler(); });

/******************************************************************************/

const buttonPurgeAllHandler = async hard => {
await vAPI.messaging.send('dashboard', {
what: 'purgeAllCaches',
hard,
});
renderFilterLists(true);
};

dom.on('#buttonPurgeAll', 'click', ev => { buttonPurgeAllHandler(ev.shiftKey); });

/******************************************************************************/

const userSettingCheckboxChanged = ( ) => {
const target = event.target;
vAPI.messaging.send('dashboard', {
Expand Down Expand Up @@ -863,6 +850,12 @@ self.hasUnsavedData = function() {

/******************************************************************************/

renderFilterLists();
renderFilterLists().then(( ) => {
const buttonUpdate = qs$('#buttonUpdate');
if ( dom.cl.has(buttonUpdate, 'active') ) { return; }
if ( dom.cl.has(buttonUpdate, 'disabled') ) { return; }
if ( listsetDetails.autoUpdate !== true ) { return; }
buttonUpdateHandler();
});

/******************************************************************************/
33 changes: 26 additions & 7 deletions src/js/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const reIsUserAsset = /^user-/;
const errorCantConnectTo = i18n$('errorCantConnectTo');
const MS_PER_HOUR = 60 * 60 * 1000;
const MS_PER_DAY = 24 * MS_PER_HOUR;
const MINUTES_PER_DAY = 24 * 60;
const EXPIRES_DEFAULT = 7;

const assets = {};
Expand Down Expand Up @@ -175,6 +176,23 @@ const isDiffUpdatableAsset = content => {
data.diffPath.startsWith('%') === false;
};

const computedPatchUpdateTime = assetKey => {
const entry = assetCacheRegistry[assetKey];
if ( entry === undefined ) { return 0; }
if ( typeof entry.diffPath !== 'string' ) { return 0; }
if ( typeof entry.diffExpires !== 'number' ) { return 0; }
const match = /(\d+)\.(\d+)\.(\d+)\.(\d+)/.exec(entry.diffPath);
if ( match === null ) { return getWriteTime(); }
const date = new Date();
date.setUTCFullYear(
parseInt(match[1], 10),
parseInt(match[2], 10) - 1,
parseInt(match[3], 10)
);
date.setUTCHours(0, parseInt(match[4], 10) + entry.diffExpires * MINUTES_PER_DAY, 0, 0);
return date.getTime();
};

/******************************************************************************/

// favorLocal: avoid making network requests whenever possible
Expand Down Expand Up @@ -1169,7 +1187,7 @@ assets.getUpdateAges = async function(conditions = {}) {
out.push({
assetKey,
age,
ageNormalized: age / getUpdateAfterTime(assetKey),
ageNormalized: age / Math.max(1, getUpdateAfterTime(assetKey)),
});
}
return out;
Expand Down Expand Up @@ -1221,12 +1239,13 @@ async function diffUpdater() {
const assetDetails = getAssetDiffDetails(assetKey);
if ( assetDetails === undefined ) { continue; }
assetDetails.what = 'update';
if ( (getWriteTime(assetKey) + assetDetails.diffExpires) > now ) {
assetDetails.fetch = false;
toSoftUpdate.push(assetDetails);
} else {
const computedUpdateTime = computedPatchUpdateTime(assetKey);
if ( computedUpdateTime !== 0 && computedUpdateTime <= now ) {
assetDetails.fetch = true;
toHardUpdate.push(assetDetails);
} else {
assetDetails.fetch = false;
toSoftUpdate.push(assetDetails);
}
}
if ( toHardUpdate.length === 0 ) { return; }
Expand Down Expand Up @@ -1432,8 +1451,8 @@ function updateDone() {

assets.updateStart = function(details) {
const oldUpdateDelay = updaterAssetDelay;
const newUpdateDelay = typeof details.delay === 'number'
? details.delay
const newUpdateDelay = typeof details.fetchDelay === 'number'
? details.fetchDelay
: updaterAssetDelayDefault;
updaterAssetDelay = Math.min(oldUpdateDelay, newUpdateDelay);
updaterAuto = details.auto === true;
Expand Down
36 changes: 22 additions & 14 deletions src/js/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ dom.on('#console-unfold', 'click', ( ) => {
dom.on('#snfe-dump', 'click', ev => {
const button = ev.target;
dom.attr(button, 'disabled', '');
vAPI.messaging.send('dashboard', {
vAPI.messaging.send('devTools', {
what: 'snfeDump',
}).then(result => {
log(result);
Expand All @@ -145,14 +145,33 @@ dom.on('#snfe-dump', 'click', ev => {
dom.on('#snfe-todnr', 'click', ev => {
const button = ev.target;
dom.attr(button, 'disabled', '');
vAPI.messaging.send('dashboard', {
vAPI.messaging.send('devTools', {
what: 'snfeToDNR',
}).then(result => {
log(result);
dom.attr(button, 'disabled', null);
});
});

dom.on('#cfe-dump', 'click', ev => {
const button = ev.target;
dom.attr(button, 'disabled', '');
vAPI.messaging.send('devTools', {
what: 'cfeDump',
}).then(result => {
log(result);
dom.attr(button, 'disabled', null);
});
});

dom.on('#purge-all-caches', 'click', ( ) => {
vAPI.messaging.send('devTools', {
what: 'purgeAllCaches'
}).then(result => {
log(result);
});
});

vAPI.messaging.send('dashboard', {
what: 'getAppData',
}).then(appData => {
Expand All @@ -161,7 +180,7 @@ vAPI.messaging.send('dashboard', {
dom.on('#snfe-benchmark', 'click', ev => {
const button = ev.target;
dom.attr(button, 'disabled', '');
vAPI.messaging.send('dashboard', {
vAPI.messaging.send('devTools', {
what: 'snfeBenchmark',
}).then(result => {
log(result);
Expand All @@ -170,15 +189,4 @@ vAPI.messaging.send('dashboard', {
});
});

dom.on('#cfe-dump', 'click', ev => {
const button = ev.target;
dom.attr(button, 'disabled', '');
vAPI.messaging.send('dashboard', {
what: 'cfeDump',
}).then(result => {
log(result);
dom.attr(button, 'disabled', null);
});
});

/******************************************************************************/
2 changes: 1 addition & 1 deletion src/js/lz4.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let ttlCount = 0;
let ttlDelay = 60000;

const init = function() {
ttlDelay = µb.hiddenSettings.autoUpdateAssetFetchPeriod * 1000 + 15000;
ttlDelay = µb.hiddenSettings.autoUpdateAssetFetchPeriod * 2 * 1000;
if ( promisedInstance === undefined ) {
let flavor;
if ( µb.hiddenSettings.disableWebAssembly === true ) {
Expand Down
Loading

0 comments on commit bd7ce41

Please sign in to comment.