mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-22 03:37:25 +08:00
Optimizing Count() usage where needed.
Prevents useless queries when huge amount of data is manipulated.
This commit is contained in:
@@ -49,26 +49,26 @@ namespace Orchard.Comments.Controllers {
|
||||
options = new CommentIndexOptions();
|
||||
|
||||
// Filtering
|
||||
IContentQuery<CommentPart, CommentPartRecord> comments;
|
||||
IContentQuery<CommentPart, CommentPartRecord> commentsQuery;
|
||||
switch (options.Filter) {
|
||||
case CommentIndexFilter.All:
|
||||
comments = _commentService.GetComments();
|
||||
commentsQuery = _commentService.GetComments();
|
||||
break;
|
||||
case CommentIndexFilter.Approved:
|
||||
comments = _commentService.GetComments(CommentStatus.Approved);
|
||||
commentsQuery = _commentService.GetComments(CommentStatus.Approved);
|
||||
break;
|
||||
case CommentIndexFilter.Pending:
|
||||
comments = _commentService.GetComments(CommentStatus.Pending);
|
||||
commentsQuery = _commentService.GetComments(CommentStatus.Pending);
|
||||
break;
|
||||
case CommentIndexFilter.Spam:
|
||||
comments = _commentService.GetComments(CommentStatus.Spam);
|
||||
commentsQuery = _commentService.GetComments(CommentStatus.Spam);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var pagerShape = Shape.Pager(pager).TotalItemCount(comments.Count());
|
||||
var entries = comments
|
||||
var pagerShape = Shape.Pager(pager).TotalItemCount(commentsQuery.Count());
|
||||
var entries = commentsQuery
|
||||
.OrderByDescending<CommentPartRecord, DateTime?>(cpr => cpr.CommentDateUtc)
|
||||
.Slice(pager.GetStartIndex(), pager.PageSize)
|
||||
.ToList()
|
||||
|
Reference in New Issue
Block a user