Skip to content

Commit 45f0bee

Browse files
committed
Skip storage calculation
Current implementation is too slow
1 parent 39292b8 commit 45f0bee

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

platform/safari/Settings.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<key>DefaultValue</key>
77
<false/>
88
<key>FalseValue</key>
9-
<false/>
9+
<string>false</string>
1010
<key>Key</key>
1111
<string>open_prefs</string>
1212
<key>Secure</key>
1313
<false/>
1414
<key>Title</key>
1515
<string>Click to see the Preferences</string>
1616
<key>TrueValue</key>
17-
<true/>
17+
<string>true</string>
1818
<key>Type</key>
1919
<string>CheckBox</string>
2020
</dict>

platform/safari/vapi-background.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,23 @@
300300
if(typeof callback !== "function") {
301301
return;
302302
}
303-
var i, size = 0;
304-
for (i in this._storage) {
305-
if (!this._storage.hasOwnProperty(i)) continue;
306-
size += (this._storage[i] || '').length;
307-
}
308-
callback(size);
303+
callback(0);
304+
// Too slow:
305+
var getBytesInUseHandler = function(cacheSize) {
306+
var i, storage = settingsStorage._storage;
307+
for (i in storage) {
308+
if (!storage.hasOwnProperty(i)) continue;
309+
cacheSize += (storage[i] || '').length;
310+
}
311+
callback(cacheSize);
312+
};
313+
vAPI.cacheStorage.getBytesInUse(null, getBytesInUseHandler);
309314
}
310315
};
311316

312317
vAPI.storage = settingsStorage;
313318

314-
if(!safari.extension.settings.migratedStorage) {
319+
if(!settingsStorage.get('migratedStorage')) {
315320
var migrationMap = {
316321
"cached_asset_content://assets/user/filters.txt": "userFilters"
317322
};
@@ -354,7 +359,7 @@
354359
delayed = null;
355360
vAPI.storage = settingsStorage;
356361
});
357-
safari.extension.settings.migratedStorage = true;
362+
settingsStorage.set({ 'migratedStorage': true });
358363
}
359364

360365
/******************************************************************************/

0 commit comments

Comments
 (0)