# HG changeset patch # User Marcin Kuzminski # Date 2020-10-06 12:14:01 # Node ID ed3be68212029d497c891d5389928a854258d1c7 # Parent 7d9c5b92bebead1886b81a45b11449f01b12a945 pull-requests: use count only for comments related to display grids on my account and repo view. diff --git a/rhodecode/apps/my_account/views/my_account.py b/rhodecode/apps/my_account/views/my_account.py --- a/rhodecode/apps/my_account/views/my_account.py +++ b/rhodecode/apps/my_account/views/my_account.py @@ -734,8 +734,8 @@ class MyAccountView(BaseAppView, DataGri comments_model = CommentsModel() for pr in pull_requests: repo_id = pr.target_repo_id - comments = comments_model.get_all_comments( - repo_id, pull_request=pr) + comments_count = comments_model.get_all_comments( + repo_id, pull_request=pr, count_only=True) owned = pr.user_id == self._rhodecode_user.user_id data.append({ @@ -760,8 +760,8 @@ class MyAccountView(BaseAppView, DataGri 'author': _render('pullrequest_author', pr.author.full_contact, ), 'author_raw': pr.author.full_name, - 'comments': _render('pullrequest_comments', len(comments)), - 'comments_raw': len(comments), + 'comments': _render('pullrequest_comments', comments_count), + 'comments_raw': comments_count, 'closed': pr.is_closed(), 'owned': owned }) diff --git a/rhodecode/apps/repository/views/repo_pull_requests.py b/rhodecode/apps/repository/views/repo_pull_requests.py --- a/rhodecode/apps/repository/views/repo_pull_requests.py +++ b/rhodecode/apps/repository/views/repo_pull_requests.py @@ -105,8 +105,8 @@ class RepoPullRequestsView(RepoAppView, data = [] comments_model = CommentsModel() for pr in pull_requests: - comments = comments_model.get_all_comments( - self.db_repo.repo_id, pull_request=pr) + comments_count = comments_model.get_all_comments( + self.db_repo.repo_id, pull_request=pr, count_only=True) data.append({ 'name': _render('pullrequest_name', @@ -127,8 +127,8 @@ class RepoPullRequestsView(RepoAppView, 'author': _render('pullrequest_author', pr.author.full_contact, ), 'author_raw': pr.author.full_name, - 'comments': _render('pullrequest_comments', len(comments)), - 'comments_raw': len(comments), + 'comments': _render('pullrequest_comments', comments_count), + 'comments_raw': comments_count, 'closed': pr.is_closed(), }) diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py --- a/rhodecode/model/comment.py +++ b/rhodecode/model/comment.py @@ -541,17 +541,20 @@ class CommentsModel(BaseModel): return comment - def get_all_comments(self, repo_id, revision=None, pull_request=None): + def get_all_comments(self, repo_id, revision=None, pull_request=None, count_only=False): q = ChangesetComment.query()\ .filter(ChangesetComment.repo_id == repo_id) if revision: q = q.filter(ChangesetComment.revision == revision) elif pull_request: pull_request = self.__get_pull_request(pull_request) - q = q.filter(ChangesetComment.pull_request == pull_request) + q = q.filter(ChangesetComment.pull_request_id == pull_request.pull_request_id) else: raise Exception('Please specify commit or pull_request') q = q.order_by(ChangesetComment.created_on) + if count_only: + return q.count() + return q.all() def get_url(self, comment, request=None, permalink=False, anchor=None):