Mercurial > kallithea
changeset 6496:89eb2b2da3c5
model: refactor listing of commenters
The ChangesetComment.get_users method was only called in two places,
with each call triggering independent codepaths inside the method.
author | Søren Løvborg <sorenl@unity3d.com> |
---|---|
date | Tue, 07 Feb 2017 21:16:13 +0100 |
parents | 2e8a87a085c5 |
children | aa6ac7ab93d1 |
files | kallithea/model/comment.py kallithea/model/db.py |
diffstat | 2 files changed, 18 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/comment.py Mon Jan 30 20:04:20 2017 +0100 +++ b/kallithea/model/comment.py Tue Feb 07 21:16:13 2017 +0100 @@ -41,6 +41,19 @@ log = logging.getLogger(__name__) +def _list_changeset_commenters(revision): + return (Session().query(User) + .join(ChangesetComment.author) + .filter(ChangesetComment.revision == revision) + .all()) + +def _list_pull_request_commenters(pull_request): + return (Session().query(User) + .join(ChangesetComment.author) + .filter(ChangesetComment.pull_request_id == pull_request.pull_request_id) + .all()) + + class ChangesetCommentsModel(BaseModel): def _get_notification_data(self, repo, comment, author, comment_text, @@ -75,14 +88,15 @@ comment_url) ) # get the current participants of this changeset - recipients = ChangesetComment.get_users(revision=revision) + recipients = _list_changeset_commenters(revision) # add changeset author if it's known locally cs_author = User.get_from_cs_author(cs.author) if not cs_author: #use repo owner if we cannot extract the author correctly # FIXME: just use committer name even if not a user cs_author = repo.owner - recipients += [cs_author] + recipients.append(cs_author) + email_kwargs = { 'status_change': status_change, 'cs_comment_user': author.full_name_and_username, @@ -122,12 +136,8 @@ comment_url) ) # get the current participants of this pull request - recipients = ChangesetComment.get_users(pull_request_id= - pull_request.pull_request_id) - # add pull request author - recipients += [pull_request.owner] - - # add the reviewers to notification + recipients = _list_pull_request_commenters(pull_request) + recipients.append(pull_request.owner) recipients += pull_request.get_reviewer_users() #set some variables for email notification
--- a/kallithea/model/db.py Mon Jan 30 20:04:20 2017 +0100 +++ b/kallithea/model/db.py Tue Feb 07 21:16:13 2017 +0100 @@ -2224,23 +2224,6 @@ cascade="all, delete-orphan", lazy='joined') pull_request = relationship('PullRequest') - @classmethod - def get_users(cls, revision=None, pull_request_id=None): - """ - Returns user associated with this ChangesetComment. ie those - who actually commented - - :param cls: - :param revision: - """ - q = Session().query(User) \ - .join(ChangesetComment.author) - if revision is not None: - q = q.filter(cls.revision == revision) - elif pull_request_id is not None: - q = q.filter(cls.pull_request_id == pull_request_id) - return q.all() - def url(self): anchor = "comment-%s" % self.comment_id import kallithea.lib.helpers as h