Skip to content

Commit

Permalink
Optimized checkExists query
Browse files Browse the repository at this point in the history
Now 30x faster!
  • Loading branch information
thinkroth committed Dec 21, 2011
1 parent d59b2a7 commit 4a15a26
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions models/ShortURL.js
Expand Up @@ -23,14 +23,12 @@ var ShortURL = mongoose.model("ShortURL", ShortURLSchema);

// return count, if it exists, try another
ShortURL.checkExists = function(hash, callback) {
var query = ShortURL.find({});
query.where("hash", hash);
query.exec(function(error, shortenedURLS) {
var query = ShortURL.find({"hash": hash}, [hash], function (error, shortenedURLS) {
if (error) {
callback(error, null);
} else {
callback(null, shortenedURLS);
};
}
});
};

Expand All @@ -47,12 +45,12 @@ ShortURL.findByHash = function(hash, callback) {
callback(error, null);
} else {
callback(null, URL);
};
}
});
} else {
callback(null, null);
}
};
}
});
};

Expand Down

0 comments on commit 4a15a26

Please sign in to comment.