fix many queries in story

This commit is contained in:
Berkeley Martinez
2015-06-23 16:28:16 -07:00
parent fb04a022ae
commit 31eb81bf2f

View File

@ -43,7 +43,10 @@ module.exports = function(app) {
} }
function hotJSON(req, res, next) { function hotJSON(req, res, next) {
Story.find({order: 'timePosted DESC', limit: 1000}, function(err, stories) { Story.find({
order: 'timePosted DESC',
limit: 1000
}, function(err, stories) {
if (err) { if (err) {
return next(err); return next(err);
} }
@ -127,7 +130,7 @@ module.exports = function(app) {
var storyName = dashedName.replace(/\-/g, ' ').trim(); var storyName = dashedName.replace(/\-/g, ' ').trim();
Story.find({where: {'storyLink': storyName}}, function(err, story) { Story.find({ where: { storyLink: storyName } }, function(err, story) {
if (err) { if (err) {
return next(err); return next(err);
} }
@ -225,7 +228,7 @@ module.exports = function(app) {
function upvote(req, res, next) { function upvote(req, res, next) {
var data = req.body.data; var data = req.body.data;
Story.find({'id': data.id}, function(err, story) { Story.find({ where: { id: data.id } }, function(err, story) {
if (err) { if (err) {
return next(err); return next(err);
} }
@ -267,7 +270,7 @@ module.exports = function(app) {
function comments(req, res, next) { function comments(req, res, next) {
var data = req.params.id; var data = req.params.id;
Comment.find( Comment.find(
{ where: {'id': data } }, { where: { id: data } },
function(err, comment) { function(err, comment) {
if (err) { if (err) {
return next(err); return next(err);
@ -300,7 +303,7 @@ module.exports = function(app) {
url = 'http://' + url; url = 'http://' + url;
} }
Story.find( Story.find(
{ where: {'link': url} }, { where: { link: url } },
function(err, story) { function(err, story) {
if (err) { if (err) {
return next(err); return next(err);
@ -357,7 +360,10 @@ module.exports = function(app) {
} }
Story.count({ Story.count({
storyLink: { like: new RegExp('^' + storyLink + '(?: [0-9]+)?$', 'i') } storyLink: {
like: ('^' + storyLink + '(?: [0-9]+)?$'),
options: 'i'
}
}, function (err, storyCount) { }, function (err, storyCount) {
if (err) { if (err) {
return next(err); return next(err);
@ -495,7 +501,7 @@ module.exports = function(app) {
function commentEdit(req, res, next) { function commentEdit(req, res, next) {
Comment.find({ id: req.params.id }, function(err, cmt) { Comment.find({ where: { id: req.params.id } }, function(err, cmt) {
if (err) { if (err) {
return next(err); return next(err);
} }
@ -538,7 +544,7 @@ module.exports = function(app) {
// Based on the context retrieve the parent // Based on the context retrieve the parent
// object of the comment (Story/Comment) // object of the comment (Story/Comment)
Context.find({ Context.find({
id: data.associatedPost where: { id: data.associatedPost }
}, function (err, associatedContext) { }, function (err, associatedContext) {
if (err) { if (err) {
return next(err); return next(err);
@ -555,7 +561,7 @@ module.exports = function(app) {
} }
// Find the author of the parent object // Find the author of the parent object
User.findOne({ User.findOne({
'profile.username': associatedContext.author.username username: associatedContext.author.username
}, function(err, recipient) { }, function(err, recipient) {
if (err) { if (err) {
return next(err); return next(err);