Closed Bug 715019 Opened 8 years ago Closed 8 years ago

IndexedDB: data take twice more space than in Chrome

Categories

(Core :: DOM: IndexedDB, defect)

x86
Windows XP
defect
Not set

Tracking

()

RESOLVED DUPLICATE of bug 703660

People

(Reporter: mett.work, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11

Steps to reproduce:

Stored data in an indexedDB



Expected results:

For the same application, the indexedDB data for Firefox take 92.8 Mb,
and for Chrome 45.8 Mb

It's not really a bug, more like an improvement, but the difference between FF and Chrome is *huge*. I restrict my users on the Intranet to use Chrome for that reason.
Can you test with a Nightly build?  We added compression for IndexedDB data recently.
In the nightly I have the error below (in Firebug). What should I do ?

This error occurred because an operation was not allowed on an object. A retry of the same operation would fail unless the cause of the error is corrected.

[Break On This Error] var request = window.indexedDB.open(databaseName, "Dokagenda local cache");
Ah, yes, the IndexedDB API changed a bit with Firefox 10.  Instead of

request = indexedDB.open(name, description);
request.onsuccess = function(event) {
  db = event.target.result;
  setversionrequest = db.setVersion(version);
  setversionrequest.onsuccess = function(event) {
    // Do your VERSION_CHANGE transaction here.
  }
}

It looks like

request = indexedDB.open(name, version);
request.onupgradeneeded = function(event) {
  db = event.target.result;
  // Do your VERSION change transaction here.
}

Chrome should be changing to match sometime soon.
I still need a little bit help before I can make a test for the original question... I did exactly what you told me and got the following exception:

"A mutation operation was attempted on a database that did not allow mutations."
NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR
NOT_ALLOWED_ERR

[...]
var request = window.indexedDB.open(databaseName, version);
request.onupgradeneeded = function(event) {
	myDB.db = e.target.result;
	var db = myDB.db;
	console.log('Database opened, version ' + db.version);
	// Do your VERSION change transaction here.
	myDB.changeVersion(db);
}
[...]
myDB.changeVersion = function(db) {
	var store = db.createObjectStore("months", {keyPath: "conKey"});
	store = db.createObjectStore("days", {keyPath: "conKey"});
	store = db.createObjectStore("components", {keyPath: "id"});
	myDB.initArrayCacheMonthValues(false);
};
[...]
var db = myDB.db;
var trans;
try {
	trans = db.transaction(["monthsVersion", "days"], IDBTransaction.READ_WRITE);
} catch (e) {
	console.log(e); // the exception is printed here
}
[...]
it's a pitty that I can't update comments.
trans = db.transaction(["monthsVersion", "days"], IDBTransaction.READ_WRITE);
should be 
trans = db.transaction(["months", "days"], IDBTransaction.READ_WRITE);
Are you waiting until request.onsuccess gets called to create the transaction?  I don't think you can create transactions until that even fires.
Thank you.

Results: Volume size went down to 10 Mb !!!

Good job :)
Excellent.  I'm going to close this bug as a duplicate of the bug that implemented compression.  It should be in Firefox 11 which will arrive sometime in March.

Thanks for the testing.
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 703660
Is there any way to know wether the user has the old "open()" specification of IDBFactory or the new one?
(In reply to Mathieu from comment #9)
> Is there any way to know wether the user has the old "open()" specification
> of IDBFactory or the new one?

Call it the old way, open("name", "description"), and if that throws then they have the new version.  Note that you have to pass a string description, because the new syntax accepts open("name", version) and open("name") (the latter opens whatever version already exists).
Component: DOM → DOM: IndexedDB
Version: 8 Branch → unspecified
You need to log in before you can comment on or make changes to this bug.