Skip to content

Commit

Permalink
[models:law] Updated lawId index and improved save handler. Related to
Browse files Browse the repository at this point in the history
  • Loading branch information
jfresco committed Dec 10, 2014
1 parent 586eefe commit b14f007
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
11 changes: 3 additions & 8 deletions lib/db-api/law.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,10 @@ function createLaw(data, fn) {
law.save(onsave);

function onsave(err) {
if (!err) return log('Saved law %s', law.id), fn(null, law);
if (err) return log('Found error %s', err), fn(err);

if (11000 == err.code) {
log('Attempt of duplication');
exports.searchOne(law._id, fn);
} else {
log('Found error %s', err);
fn(err);
}
log('Saved law %s', law.id);
fn(null, law);
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/models/law.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ LawSchema.index({ createdAt: -1 });
LawSchema.index({ closingAt: -1 });
LawSchema.index({ participants: -1 });
LawSchema.index({ tag: -1 });
LawSchema.index({ state: 1, lawId: 1 });
LawSchema.index({ lawId: -1 });

/**
* Make Schema `.toObject()` and
Expand Down

0 comments on commit b14f007

Please sign in to comment.