Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/prefs.js

Issue 29555660: Issue 5769 - Worked around bad Firefox 55 storage performance (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome
Patch Set: Created Sept. 25, 2017, 10:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return null; 231 return null;
232 232
233 return key.substr(keyPrefix.length); 233 return key.substr(keyPrefix.length);
234 } 234 }
235 235
236 function prefToKey(pref) 236 function prefToKey(pref)
237 { 237 {
238 return keyPrefix + pref; 238 return keyPrefix + pref;
239 } 239 }
240 240
241 function savePref(pref)
242 {
243 ext.storage.set(prefToKey(pref), overrides[pref]);
244 }
245
246 let customSave = new Map();
247 if (require("info").platform == "gecko")
248 {
249 // Saving one storage value causes all others to be saved as well on Gecko.
250 // Make sure that updating ad counter doesn't cause the filters data to be
251 // saved frequently as a side-effect.
252 const MIN_UPDATE_INTERVAL = 60 * 1000;
253 let lastUpdate = -MIN_UPDATE_INTERVAL;
254 let updateScheduled = false;
255 customSave.set("blocked_total", pref =>
256 {
257 if (updateScheduled)
258 return;
259
260 let callback = () =>
261 {
262 lastUpdate = performance.now();
263 updateScheduled = false;
264 savePref(pref);
265 };
266
267 let timeElapsed = performance.now() - lastUpdate;
268 if (timeElapsed < MIN_UPDATE_INTERVAL)
269 {
270 setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed);
271 updateScheduled = true;
272 }
273 else
274 callback();
275 });
276 }
277
241 function addPreference(pref) 278 function addPreference(pref)
242 { 279 {
243 Object.defineProperty(Prefs, pref, { 280 Object.defineProperty(Prefs, pref, {
244 get() { return (pref in overrides ? overrides : defaults)[pref]; }, 281 get() { return (pref in overrides ? overrides : defaults)[pref]; },
245 set(value) 282 set(value)
246 { 283 {
247 let defaultValue = defaults[pref]; 284 let defaultValue = defaults[pref];
248 285
249 if (typeof value != typeof defaultValue) 286 if (typeof value != typeof defaultValue)
250 throw new Error("Attempt to change preference type"); 287 throw new Error("Attempt to change preference type");
251 288
252 if (value == defaultValue) 289 if (value == defaultValue)
253 { 290 {
254 delete overrides[pref]; 291 delete overrides[pref];
255 ext.storage.remove(prefToKey(pref)); 292 ext.storage.remove(prefToKey(pref));
256 } 293 }
257 else 294 else
258 { 295 {
259 overrides[pref] = value; 296 overrides[pref] = value;
260 ext.storage.set(prefToKey(pref), value); 297 (customSave.get(pref) || savePref)(pref);
261 } 298 }
262 }, 299 },
263 enumerable: true 300 enumerable: true
264 }); 301 });
265 } 302 }
266 303
267 function init() 304 function init()
268 { 305 {
269 let prefs = Object.keys(defaults); 306 let prefs = Object.keys(defaults);
270 prefs.forEach(addPreference); 307 prefs.forEach(addPreference);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 eventEmitter.emit(pref); 359 eventEmitter.emit(pref);
323 } 360 }
324 } 361 }
325 }); 362 });
326 } 363 }
327 364
328 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); 365 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded);
329 } 366 }
330 367
331 init(); 368 init();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld