comment count optim, prep for sortBy

This commit is contained in:
Wyatt Johnson
2017-08-21 15:26:04 -06:00
parent 15111c81a2
commit 01ed9880f4
11 changed files with 93 additions and 282 deletions
+24 -16
View File
@@ -4,9 +4,6 @@ const {
} = require('../../perms/constants');
const Asset = {
recentComments({id}, _, {loaders: {Comments}}) {
return Comments.genRecentComments.load(id);
},
async comment({id}, {id: commentId}, {loaders: {Comments}, user}) {
const statuses = user && user.can(SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS)
? ['NONE', 'ACCEPTED', 'PREMOD', 'REJECTED']
@@ -20,7 +17,7 @@ const Asset = {
return comments.nodes[0];
},
comments({id}, {sort, limit, deep, excludeIgnored, tags}, {loaders: {Comments}}) {
comments({id}, {query: {sort, limit, excludeIgnored, tags}, deep}, {loaders: {Comments}}) {
return Comments.getByQuery({
asset_id: id,
sort,
@@ -30,26 +27,37 @@ const Asset = {
excludeIgnored,
});
},
commentCount({id, commentCount}, {excludeIgnored, tags}, {user, loaders: {Comments}}) {
// TODO: remove
if ((user && excludeIgnored) || tags) {
return Comments.parentCountByAssetIDPersonalized({assetId: id, excludeIgnored, tags});
}
commentCount({id, commentCount}, {tags}, {loaders: {Comments}}) {
if (commentCount != null) {
return commentCount;
}
// If we are filtering by a tag.
if (tags && tags.length > 0) {
// Then count the comments with those tags.
return Comments.getCountByQuery({
tags,
asset_id: id,
parent_id: id,
statuses: ['NONE', 'ACCEPTED'],
});
}
return Comments.parentCountByAssetID.load(id);
},
totalCommentCount({id, totalCommentCount}, {excludeIgnored, tags}, {user, loaders: {Comments}}) {
// TODO: remove
if ((user && excludeIgnored) || tags) {
return Comments.countByAssetIDPersonalized({assetId: id, excludeIgnored, tags});
}
totalCommentCount({id, totalCommentCount}, {tags}, {loaders: {Comments}}) {
if (totalCommentCount != null) {
return totalCommentCount;
}
// If we are filtering by a tag.
if (tags && tags.length > 0) {
// Then count the comments with those tags.
return Comments.getCountByQuery({tags, asset_id: id, statuses: ['NONE', 'ACCEPTED']});
}
return Comments.countByAssetID.load(id);
},
async settings({settings = null}, _, {loaders: {Settings}}) {
+16 -14
View File
@@ -11,10 +11,16 @@ const Comment = {
user({author_id}, _, {loaders: {Users}}) {
return Users.getByID.load(author_id);
},
recentReplies({id}, _, {loaders: {Comments}}) {
return Comments.genRecentReplies.load(id);
},
replies({id, asset_id}, {sort, limit, excludeIgnored}, {loaders: {Comments}}) {
replies({id, asset_id, reply_count}, {query: {sort, limit, excludeIgnored}}, {loaders: {Comments}}) {
// Don't bother looking up replies if there aren't any there!
if (reply_count === 0) {
return {
nodes: [],
hasNextPage: false,
};
}
return Comments.getByQuery({
asset_id,
parent_id: id,
@@ -23,21 +29,17 @@ const Comment = {
excludeIgnored,
});
},
replyCount({id}, {excludeIgnored}, {user, loaders: {Comments}}) {
replyCount({reply_count}) {
// TODO: remove
if (user && excludeIgnored) {
return Comments.countByParentIDPersonalized({id, excludeIgnored});
}
return Comments.countByParentID.load(id);
// A simple remap from the underlying database model to the graph model.
return reply_count;
},
actions({id}, _, {user, loaders: {Actions}}) {
if (user && user.can('SEARCH_ACTIONS')) {
return Actions.getByID.load(id);
if (!user || !user.can('SEARCH_ACTIONS')) {
return null;
}
return null;
return Actions.getByID.load(id);
},
action_summaries({id, action_summaries}, _, {loaders: {Actions}}) {
if (action_summaries) {