Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Use a flag to support IndexedDB getAll() optimization.
Browse files Browse the repository at this point in the history
IndexedDB IDBObjectStore.getAll() has limitations in Chrome that
database file larger than certain amount (>150MB) will cause
browser crash. Use this flag to guard it so that users can choose
to turn on/off this feature for their usage.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221745579
  • Loading branch information
arthurhsu authored and freshp86 committed Jun 4, 2019
1 parent ab591df commit 3d0386c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/lovefield.es6.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/lovefield.js
Original file line number Diff line number Diff line change
Expand Up @@ -3753,6 +3753,7 @@ lf.Flags = {};
lf.Flags.MEMORY_ONLY = !1;
lf.Flags.NATIVE_ES6 = !1;
lf.Flags.EXCEPTION_URL = "http://google.github.io/lovefield/error_lookup/src/error_lookup.html?c=";
lf.Flags.IDB_GETALL_OPTIMIZATION = !0;
lf.structs = {};
lf.structs.map = {};
$jscomp.scope.detectUseNative = function() {
Expand Down Expand Up @@ -6361,7 +6362,7 @@ lf.backstore.ObjectStore = function(store, deserializeFn) {
};
lf.backstore.ObjectStore.prototype.get = function(ids) {
if (0 == ids.length) {
return goog.isDefAndNotNull(this.store_.getAll) ? this.getAllBulk_() : this.getAllWithCursor_();
return lf.Flags.IDB_GETALL_OPTIMIZATION && goog.isDefAndNotNull(this.store_.getAll) ? this.getAllBulk_() : this.getAllWithCursor_();
}
var promises = ids.map(function(id) {
return new goog.Promise(function(resolve, reject) {
Expand Down
2 changes: 1 addition & 1 deletion dist/lovefield.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/backstore/object_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
goog.provide('lf.backstore.ObjectStore');

goog.require('goog.Promise');
goog.require('lf.Flags');
goog.require('lf.Table');


Expand All @@ -43,7 +44,8 @@ lf.backstore.ObjectStore = function(store, deserializeFn) {
/** @override */
lf.backstore.ObjectStore.prototype.get = function(ids) {
if (ids.length == 0) {
return goog.isDefAndNotNull(this.store_['getAll']) ?
return lf.Flags.IDB_GETALL_OPTIMIZATION &&
goog.isDefAndNotNull(this.store_['getAll']) ?
this.getAllBulk_() : this.getAllWithCursor_();
}

Expand Down
9 changes: 9 additions & 0 deletions lib/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ lf.Flags.NATIVE_ES6 = false;
lf.Flags.EXCEPTION_URL =
'http://google.github.io/lovefield/error_lookup/src/error_lookup.html?c=';


/**
* Allows IDBObjectStore.getAll optimization.
* @define {boolean} When set to true, Lovefield will use IDBObjectStore.getAll
* whenever available. This value is suggested to be set to false, see
* https://crbug.com/868177 for more details.
*/
lf.Flags.IDB_GETALL_OPTIMIZATION = true;

0 comments on commit 3d0386c

Please sign in to comment.