Skip to content

Commit

Permalink
Improve performances (get over findOne when possible)
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo mathieu committed Mar 21, 2016
1 parent 369dde8 commit 409c7a4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@ export default function(name) {

return {
find(selector, options) {
if(typeof selector == 'string') return [Data.db[name].findOne({_id: selector}, options)];
if(typeof selector == 'string') {
if(options) {
return [Data.db[name].findOne({_id: selector}, options)];
} else {
return [Data.db[name].get(selector)];
}
}
return Data.db[name].find(selector, options);

},
findOne(selector, options) {
if(typeof selector == 'string') return Data.db[name].findOne({_id: selector}, options);

if(typeof selector == 'string') {
if(options) {
return Data.db[name].findOne({_id: selector}, options);
} else {
return Data.db[name].get(selector);
}
}
return Data.db[name] && Data.db[name].findOne(selector, options)

},
Expand Down

0 comments on commit 409c7a4

Please sign in to comment.