Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); | 20 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
21 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); | 21 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); |
22 const {DownloadableSubscription, | 22 const {DownloadableSubscription, SpecialSubscription} = |
23 SpecialSubscription} = | |
24 require("../adblockpluscore/lib/subscriptionClasses"); | 23 require("../adblockpluscore/lib/subscriptionClasses"); |
Sebastian Noack
2018/09/04 21:00:01
Nit: No reason to wrap twice here (also more consi
geo
2018/09/05 14:04:33
Done.
| |
25 | 24 |
26 const BACKUP_NAME = "file:indexedDB-backup"; | 25 const BACKUP_NAME = "file:indexedDB-backup"; |
27 | 26 |
28 let minWriteInterval; | 27 let backupDelay; |
29 let lastBackup; | 28 let pendingBackup = false; |
30 let lastRun = -minWriteInterval; | |
31 | 29 |
32 function setBackupInterval(backupInterval = 60 * 1000) | 30 function setBackupInterval(backupInterval = 60 * 1000) |
33 { | 31 { |
34 minWriteInterval = backupInterval; | 32 backupDelay = backupInterval; |
35 } | 33 } |
36 | 34 |
37 setBackupInterval(); | 35 setBackupInterval(); |
38 | 36 |
39 function scheduleBackup() | 37 function scheduleBackup() |
40 { | 38 { |
41 if (!lastBackup) | 39 if (!pendingBackup) |
42 { | 40 { |
43 lastBackup = setTimeout( | 41 pendingBackup = true; |
Sebastian Noack
2018/09/04 21:00:01
It seems now the only reason to have the lastBacku
geo
2018/09/05 14:04:33
Done.
| |
42 | |
43 setTimeout( | |
44 () => | 44 () => |
45 { | 45 { |
46 saveToStorage(); | 46 saveToStorage(); |
47 lastBackup = null; | 47 pendingBackup = false; |
48 lastRun = performance.now(); | |
49 }, | 48 }, |
50 lastRun + minWriteInterval - performance.now() | 49 backupDelay |
Sebastian Noack
2018/09/04 21:00:01
Just an idea, I'm wondering if a simpler throttlin
geo
2018/09/05 14:04:33
Yup, it does make things simpler. And you are prob
| |
51 ); | 50 ); |
52 } | 51 } |
53 } | 52 } |
54 | 53 |
55 function saveToStorage() | 54 function saveToStorage() |
56 { | 55 { |
57 browser.storage.local.set({ | 56 browser.storage.local.set({ |
58 [BACKUP_NAME]: { | 57 [BACKUP_NAME]: { |
59 content: serialize(), | 58 content: serialize(), |
60 lastModified: Date.now() | 59 lastModified: Date.now() |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 FilterNotifier.on("filter.removed", scheduleBackup); | 110 FilterNotifier.on("filter.removed", scheduleBackup); |
112 FilterNotifier.on("filter.moved", scheduleBackup); | 111 FilterNotifier.on("filter.moved", scheduleBackup); |
113 FilterNotifier.on("filter.disabled", scheduleBackup); | 112 FilterNotifier.on("filter.disabled", scheduleBackup); |
114 | 113 |
115 exports.IndexedDBBackup = | 114 exports.IndexedDBBackup = |
116 { | 115 { |
117 getBackupData, | 116 getBackupData, |
118 // Non-public API, just for tests. | 117 // Non-public API, just for tests. |
119 setBackupInterval | 118 setBackupInterval |
120 }; | 119 }; |
LEFT | RIGHT |