Skip to content

Commit bd7ce41

Browse files
committed
Remove "Purge all caches" button from "Filter lists" pane
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.
1 parent 1492691 commit bd7ce41

11 files changed

+273
-202
lines changed

src/3p-filters.html

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<div id="actions">
2121
<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>
2222
<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>
23-
<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>
2423
</div>
2524

2625
<div>

src/devtools.html

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<button id="snfe-todnr" type="button">SNFE: DNR<span class="hover"></span></button>
3030
<button id="snfe-benchmark" type="button" disabled>SNFE: Benchmark<span class="hover"></span></button>
3131
<button id="cfe-dump" type="button">CFE: Dump<span class="hover"></span></button>
32+
<button id="purge-all-caches" type="button" data-i18n-title="3pPurgeAll"><span data-i18n="3pPurgeAll">_</span><span class="hover"></span></button>
3233
</div>
3334
<div id="console" class="codeMirrorContainer"></div>
3435

src/js/3p-filters.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ const renderFilterLists = ( ) => {
276276
renderWidgets();
277277
};
278278

279-
vAPI.messaging.send('dashboard', {
279+
return vAPI.messaging.send('dashboard', {
280280
what: 'getLists',
281281
}).then(response => {
282282
onListsReceived(response);
@@ -295,9 +295,6 @@ const renderWidgets = ( ) => {
295295
updating === false &&
296296
qs$('#lists .listEntry.checked.obsolete:not(.toRemove)') === null
297297
);
298-
dom.cl.toggle('#buttonPurgeAll', 'disabled',
299-
updating || qs$('#lists .listEntry.cached:not(.obsolete)') === null
300-
);
301298
};
302299

303300
/******************************************************************************/
@@ -510,15 +507,17 @@ const onPurgeClicked = ev => {
510507
}
511508

512509
vAPI.messaging.send('dashboard', {
513-
what: 'purgeCaches',
510+
what: 'listsUpdateNow',
514511
assetKeys,
512+
preferOrigin: ev.shiftKey,
515513
});
516514

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

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

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

616615
/******************************************************************************/
617616

618-
const buttonPurgeAllHandler = async hard => {
619-
await vAPI.messaging.send('dashboard', {
620-
what: 'purgeAllCaches',
621-
hard,
622-
});
623-
renderFilterLists(true);
624-
};
625-
626-
dom.on('#buttonPurgeAll', 'click', ev => { buttonPurgeAllHandler(ev.shiftKey); });
627-
628-
/******************************************************************************/
629-
630617
const userSettingCheckboxChanged = ( ) => {
631618
const target = event.target;
632619
vAPI.messaging.send('dashboard', {
@@ -863,6 +850,12 @@ self.hasUnsavedData = function() {
863850

864851
/******************************************************************************/
865852

866-
renderFilterLists();
853+
renderFilterLists().then(( ) => {
854+
const buttonUpdate = qs$('#buttonUpdate');
855+
if ( dom.cl.has(buttonUpdate, 'active') ) { return; }
856+
if ( dom.cl.has(buttonUpdate, 'disabled') ) { return; }
857+
if ( listsetDetails.autoUpdate !== true ) { return; }
858+
buttonUpdateHandler();
859+
});
867860

868861
/******************************************************************************/

src/js/assets.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const reIsUserAsset = /^user-/;
3939
const errorCantConnectTo = i18n$('errorCantConnectTo');
4040
const MS_PER_HOUR = 60 * 60 * 1000;
4141
const MS_PER_DAY = 24 * MS_PER_HOUR;
42+
const MINUTES_PER_DAY = 24 * 60;
4243
const EXPIRES_DEFAULT = 7;
4344

4445
const assets = {};
@@ -175,6 +176,23 @@ const isDiffUpdatableAsset = content => {
175176
data.diffPath.startsWith('%') === false;
176177
};
177178

179+
const computedPatchUpdateTime = assetKey => {
180+
const entry = assetCacheRegistry[assetKey];
181+
if ( entry === undefined ) { return 0; }
182+
if ( typeof entry.diffPath !== 'string' ) { return 0; }
183+
if ( typeof entry.diffExpires !== 'number' ) { return 0; }
184+
const match = /(\d+)\.(\d+)\.(\d+)\.(\d+)/.exec(entry.diffPath);
185+
if ( match === null ) { return getWriteTime(); }
186+
const date = new Date();
187+
date.setUTCFullYear(
188+
parseInt(match[1], 10),
189+
parseInt(match[2], 10) - 1,
190+
parseInt(match[3], 10)
191+
);
192+
date.setUTCHours(0, parseInt(match[4], 10) + entry.diffExpires * MINUTES_PER_DAY, 0, 0);
193+
return date.getTime();
194+
};
195+
178196
/******************************************************************************/
179197

180198
// favorLocal: avoid making network requests whenever possible
@@ -1169,7 +1187,7 @@ assets.getUpdateAges = async function(conditions = {}) {
11691187
out.push({
11701188
assetKey,
11711189
age,
1172-
ageNormalized: age / getUpdateAfterTime(assetKey),
1190+
ageNormalized: age / Math.max(1, getUpdateAfterTime(assetKey)),
11731191
});
11741192
}
11751193
return out;
@@ -1221,12 +1239,13 @@ async function diffUpdater() {
12211239
const assetDetails = getAssetDiffDetails(assetKey);
12221240
if ( assetDetails === undefined ) { continue; }
12231241
assetDetails.what = 'update';
1224-
if ( (getWriteTime(assetKey) + assetDetails.diffExpires) > now ) {
1225-
assetDetails.fetch = false;
1226-
toSoftUpdate.push(assetDetails);
1227-
} else {
1242+
const computedUpdateTime = computedPatchUpdateTime(assetKey);
1243+
if ( computedUpdateTime !== 0 && computedUpdateTime <= now ) {
12281244
assetDetails.fetch = true;
12291245
toHardUpdate.push(assetDetails);
1246+
} else {
1247+
assetDetails.fetch = false;
1248+
toSoftUpdate.push(assetDetails);
12301249
}
12311250
}
12321251
if ( toHardUpdate.length === 0 ) { return; }
@@ -1432,8 +1451,8 @@ function updateDone() {
14321451

14331452
assets.updateStart = function(details) {
14341453
const oldUpdateDelay = updaterAssetDelay;
1435-
const newUpdateDelay = typeof details.delay === 'number'
1436-
? details.delay
1454+
const newUpdateDelay = typeof details.fetchDelay === 'number'
1455+
? details.fetchDelay
14371456
: updaterAssetDelayDefault;
14381457
updaterAssetDelay = Math.min(oldUpdateDelay, newUpdateDelay);
14391458
updaterAuto = details.auto === true;

src/js/devtools.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ dom.on('#console-unfold', 'click', ( ) => {
134134
dom.on('#snfe-dump', 'click', ev => {
135135
const button = ev.target;
136136
dom.attr(button, 'disabled', '');
137-
vAPI.messaging.send('dashboard', {
137+
vAPI.messaging.send('devTools', {
138138
what: 'snfeDump',
139139
}).then(result => {
140140
log(result);
@@ -145,14 +145,33 @@ dom.on('#snfe-dump', 'click', ev => {
145145
dom.on('#snfe-todnr', 'click', ev => {
146146
const button = ev.target;
147147
dom.attr(button, 'disabled', '');
148-
vAPI.messaging.send('dashboard', {
148+
vAPI.messaging.send('devTools', {
149149
what: 'snfeToDNR',
150150
}).then(result => {
151151
log(result);
152152
dom.attr(button, 'disabled', null);
153153
});
154154
});
155155

156+
dom.on('#cfe-dump', 'click', ev => {
157+
const button = ev.target;
158+
dom.attr(button, 'disabled', '');
159+
vAPI.messaging.send('devTools', {
160+
what: 'cfeDump',
161+
}).then(result => {
162+
log(result);
163+
dom.attr(button, 'disabled', null);
164+
});
165+
});
166+
167+
dom.on('#purge-all-caches', 'click', ( ) => {
168+
vAPI.messaging.send('devTools', {
169+
what: 'purgeAllCaches'
170+
}).then(result => {
171+
log(result);
172+
});
173+
});
174+
156175
vAPI.messaging.send('dashboard', {
157176
what: 'getAppData',
158177
}).then(appData => {
@@ -161,7 +180,7 @@ vAPI.messaging.send('dashboard', {
161180
dom.on('#snfe-benchmark', 'click', ev => {
162181
const button = ev.target;
163182
dom.attr(button, 'disabled', '');
164-
vAPI.messaging.send('dashboard', {
183+
vAPI.messaging.send('devTools', {
165184
what: 'snfeBenchmark',
166185
}).then(result => {
167186
log(result);
@@ -170,15 +189,4 @@ vAPI.messaging.send('dashboard', {
170189
});
171190
});
172191

173-
dom.on('#cfe-dump', 'click', ev => {
174-
const button = ev.target;
175-
dom.attr(button, 'disabled', '');
176-
vAPI.messaging.send('dashboard', {
177-
what: 'cfeDump',
178-
}).then(result => {
179-
log(result);
180-
dom.attr(button, 'disabled', null);
181-
});
182-
});
183-
184192
/******************************************************************************/

src/js/lz4.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let ttlCount = 0;
4444
let ttlDelay = 60000;
4545

4646
const init = function() {
47-
ttlDelay = µb.hiddenSettings.autoUpdateAssetFetchPeriod * 1000 + 15000;
47+
ttlDelay = µb.hiddenSettings.autoUpdateAssetFetchPeriod * 2 * 1000;
4848
if ( promisedInstance === undefined ) {
4949
let flavor;
5050
if ( µb.hiddenSettings.disableWebAssembly === true ) {

0 commit comments

Comments
 (0)