-
-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In response to issue #90, a bulk add method. Does support hook('creating') if used. This method takes special care of not keeping any closure reference to the added objects since there are many users that have had memory consumption and performance issues when adding lots of items. I would in the long term also want to create a generic bulk() method that would take an array of operations that could be a mix of add/put/update/deletes, but that will require a bit more complexity. Starting with this method to get some feedback on whether it improves performance as it is intended to do.
- Loading branch information
1 parent
b057cc6
commit 62c487a
Showing
3 changed files
with
129 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,6 +252,25 @@ | |
ok(false, "Error: " + e); | ||
}).finally(start); | ||
}); | ||
asyncTest("bulkAdd", function() { | ||
db.transaction("rw", db.users, function() { | ||
var newUsers = [ | ||
{ first: "Åke1", last: "Persbrant1", username: "aper1", email: ["[email protected]"] }, | ||
{ first: "Åke2", last: "Persbrant2", username: "aper2", email: ["[email protected]"] }, | ||
{ first: "Åke2", last: "Persbrant2", username: "aper2", email: ["[email protected]"] }, // Should fail | ||
{ first: "Åke3", last: "Persbrant3", username: "aper3", email: ["[email protected]"] } | ||
]; | ||
db.users.bulkAdd(newUsers).then(function(errors) { | ||
equal(errors.length, 1, "One error due to a duplicate username"); | ||
}); | ||
|
||
db.users.where("username").startsWith("aper").count(function(count) { | ||
equal(count, 3); | ||
}); | ||
}).catch(function (e) { | ||
ok(false, "Error: " + e); | ||
}).finally(start); | ||
}); | ||
asyncTest("delete", function () { | ||
// Without transaction | ||
db.users.get(idOfFirstUser, function (user) { | ||
|