bug fixes, removed dead code

This commit is contained in:
Wyatt Johnson
2017-08-21 16:05:35 -06:00
parent 78d4740abe
commit eec0e18600
3 changed files with 9 additions and 42 deletions
+1 -34
View File
@@ -79,38 +79,6 @@ const getParentCountsByAssetID = (context, asset_ids) => {
.then((results) => results.map((result) => result ? result.count : 0));
};
/**
* Returns the comment count for all comments that are public based on their
* parent ids.
*
* @param {Array<String>} parent_ids the ids of parents for which there are
* comments that we want to get
*/
const getCountsByParentID = (context, parent_ids) => {
return CommentModel.aggregate([
{
$match: {
parent_id: {
$in: parent_ids
},
status: {
$in: ['NONE', 'ACCEPTED']
}
}
},
{
$group: {
_id: '$parent_id',
count: {
$sum: 1
}
}
}
])
.then(singleJoinBy(parent_ids, '_id'))
.then((results) => results.map((result) => result ? result.count : 0));
};
/**
* Retrieves the count of comments based on the passed in query.
* @param {Object} context graph context
@@ -311,7 +279,6 @@ module.exports = (context) => ({
getByQuery: (query) => getCommentsByQuery(context, query),
getCountByQuery: (query) => getCommentCountByQuery(context, query),
countByAssetID: new SharedCounterDataLoader('Comments.totalCommentCount', ms(CACHE_EXPIRY_COMMENT_COUNT), (ids) => getCountsByAssetID(context, ids)),
parentCountByAssetID: new SharedCounterDataLoader('Comments.countByAssetID', ms(CACHE_EXPIRY_COMMENT_COUNT), (ids) => getParentCountsByAssetID(context, ids)),
countByParentID: new SharedCounterDataLoader('Comments.countByParentID', ms(CACHE_EXPIRY_COMMENT_COUNT), (ids) => getCountsByParentID(context, ids)),
parentCountByAssetID: new SharedCounterDataLoader('Comments.countByAssetID', ms(CACHE_EXPIRY_COMMENT_COUNT), (ids) => getParentCountsByAssetID(context, ids))
}
});
+2 -6
View File
@@ -174,9 +174,7 @@ const createComment = async (context, {tags = [], body, asset_id, parent_id = nu
// perform these increments in the event that we do have a new comment that
// is approved or without a comment.
if (status === 'NONE' || status === 'APPROVED') {
if (parent_id != null) {
Comments.countByParentID.incr(parent_id);
} else {
if (parent_id === null) {
Comments.parentCountByAssetID.incr(asset_id);
}
Comments.countByAssetID.incr(asset_id);
@@ -338,9 +336,7 @@ const setStatus = async ({user, loaders: {Comments}, pubsub}, {id, status}) => {
// be nice if we could decrement the counters here, but that would result
// in us having to know the initial state of the comment, which would
// require another database query.
if (comment.parent_id != null) {
Comments.countByParentID.clear(comment.parent_id);
} else {
if (comment.parent_id === null) {
Comments.parentCountByAssetID.clear(comment.asset_id);
}
+6 -2
View File
@@ -39,7 +39,7 @@ const Asset = {
return Comments.getCountByQuery({
tags,
asset_id: id,
parent_id: id,
parent_id: null,
statuses: ['NONE', 'ACCEPTED'],
});
}
@@ -55,7 +55,11 @@ const Asset = {
if (tags && tags.length > 0) {
// Then count the comments with those tags.
return Comments.getCountByQuery({tags, asset_id: id, statuses: ['NONE', 'ACCEPTED']});
return Comments.getCountByQuery({
tags,
asset_id: id,
statuses: ['NONE', 'ACCEPTED'],
});
}
return Comments.countByAssetID.load(id);