mirror of
https://github.com/wassname/talk.git
synced 2026-08-17 11:27:52 +08:00
added more db optims
This commit is contained in:
+18
-23
@@ -1,32 +1,27 @@
|
||||
const {decorateWithTags} = require('./util');
|
||||
const {
|
||||
SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS,
|
||||
} = require('../../perms/constants');
|
||||
|
||||
const Asset = {
|
||||
async comment({id}, {id: commentId}, {loaders: {Comments}, user}) {
|
||||
const statuses = user && user.can(SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS)
|
||||
? ['NONE', 'ACCEPTED', 'PREMOD', 'REJECTED']
|
||||
: ['NONE', 'ACCEPTED'];
|
||||
async comment({id}, {id: commentId}, {loaders: {Comments}}) {
|
||||
|
||||
const comments = await Comments.getByQuery({
|
||||
asset_id: id,
|
||||
ids: commentId,
|
||||
statuses,
|
||||
});
|
||||
// Load the comment from the database.
|
||||
const comment = Comments.get.load(id);
|
||||
if (!comment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return comments.nodes[0];
|
||||
// If the comment asset mismatches, then don't return it!
|
||||
if (comment.asset_id !== id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return comment;
|
||||
},
|
||||
comments({id}, {query: {sort, sortBy, limit, excludeIgnored, tags}, deep}, {loaders: {Comments}}) {
|
||||
return Comments.getByQuery({
|
||||
asset_id: id,
|
||||
sort,
|
||||
sortBy,
|
||||
limit,
|
||||
parent_id: deep ? undefined : null,
|
||||
tags,
|
||||
excludeIgnored,
|
||||
});
|
||||
comments({id}, {query, deep}, {loaders: {Comments}}) {
|
||||
if (!deep) {
|
||||
query.parent_id = null;
|
||||
}
|
||||
|
||||
return Comments.getByQuery(query);
|
||||
},
|
||||
commentCount({id, commentCount}, {tags}, {loaders: {Comments}}) {
|
||||
if (commentCount != null) {
|
||||
|
||||
@@ -2,9 +2,11 @@ const {SEARCH_OTHER_USERS} = require('../../perms/constants');
|
||||
|
||||
const CommentStatusHistory = {
|
||||
assigned_by({assigned_by}, _, {user, loaders: {Users}}) {
|
||||
if (user && user.can(SEARCH_OTHER_USERS) && assigned_by != null) {
|
||||
return Users.getByID.load(assigned_by);
|
||||
if (!user || !user.can(SEARCH_OTHER_USERS) || assigned_by != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Users.getByID.load(assigned_by);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@ const FlagAction = {
|
||||
return group_id;
|
||||
},
|
||||
user({user_id}, _, {loaders: {Users}}) {
|
||||
if (user_id) {
|
||||
return Users.getByID.load(user_id);
|
||||
if (!user_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Users.getByID.load(user_id);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ const RootQuery = {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {asset_url} = query;
|
||||
if (asset_url && asset_url.length > 0) {
|
||||
const {asset_url, asset_id} = query;
|
||||
if ((!asset_id || asset_id.length === 0) && asset_url && asset_url.length > 0) {
|
||||
let asset = await Assets.findByUrl(asset_url);
|
||||
if (asset) {
|
||||
query.asset_id = asset.id;
|
||||
|
||||
@@ -95,11 +95,11 @@ module.exports = class CommentsService {
|
||||
},
|
||||
});
|
||||
|
||||
if (originalComment === null) {
|
||||
if (originalComment == null) {
|
||||
|
||||
// Try to get the comment.
|
||||
const comment = await CommentsService.findById(id);
|
||||
if (comment === null) {
|
||||
if (comment == null) {
|
||||
debug('rejecting comment edit because comment was not found');
|
||||
throw errors.ErrNotFound;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ module.exports = class CommentsService {
|
||||
$set: {status}
|
||||
});
|
||||
|
||||
if (originalComment === null) {
|
||||
if (originalComment == null) {
|
||||
throw errors.ErrNotFound;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user