[PATCH V2] summary, changelog: make the comments counts more accurate

Angel Ezquerra angel.ezquerra at gmail.com
Fri Feb 26 20:56:08 UTC 2016


On Fri, Feb 26, 2016 at 2:43 PM, Thomas De Schampheleire
<patrickdepinguin at gmail.com> wrote:
> On Thu, Feb 25, 2016 at 11:44 AM, Angel Ezquerra
> <angel.ezquerra at gmail.com> wrote:
>> # HG changeset patch
>> # User Angel Ezquerra <angel.ezquerra at gmail.com>
>> # Date 1456382571 -3600
>> #      Thu Feb 25 07:42:51 2016 +0100
>> # Node ID c1fa76fe1c6fabb31d03826d946e92dd703e4243
>> # Parent  05a85a6cecba5c8caeb7996590365d5d9bc523c9
>> summary, changelog: make the comments counts more accurate
>>
>> Up until now the comment counts shown on the summary and changelog counted both
>> actual (non-empty) comments and status changes. This was not particularly
>> useful, since the status information is already shown on the status icon. Also,
>> openeing a changeset page to find out that it just had its status changed (with
>> no textual comments) is quite annoying.
>>
>> Instead, show the number of "actual" comments (i.e. those that have some comment
>> text).
>>
>> diff --git a/kallithea/controllers/changelog.py b/kallithea/controllers/changelog.py
>> --- a/kallithea/controllers/changelog.py
>> +++ b/kallithea/controllers/changelog.py
>> @@ -62,6 +62,7 @@
>>      page_revisions = [x.raw_id for x in list(c.repo_changesets)]
>>      c.comments = c.db_repo.get_comments(page_revisions)
>>      c.statuses = c.db_repo.statuses(page_revisions)
>> +    c.comment_counts = c.db_repo.count_comments(c.comments)
>>
>>
>>  class ChangelogController(BaseRepoController):
>> @@ -152,6 +153,7 @@
>>              page_revisions = [x.raw_id for x in c.pagination]
>>              c.comments = c.db_repo.get_comments(page_revisions)
>>              c.statuses = c.db_repo.statuses(page_revisions)
>> +            c.comment_counts = c.db_repo.count_comments(c.comments)
>>          except EmptyRepositoryError as e:
>>              h.flash(safe_str(e), category='warning')
>>              raise HTTPFound(location=url('summary_home', repo_name=c.repo_name))
>> diff --git a/kallithea/model/db.py b/kallithea/model/db.py
>> --- a/kallithea/model/db.py
>> +++ b/kallithea/model/db.py
>> @@ -1395,6 +1395,16 @@
>>              grouped[cmt.revision].append(cmt)
>>          return grouped
>>
>> +    def count_comments(self, comments):
>> +        """
>> +        Returns the count of (non-empty) comments for this repository grouped by revisions
>> +
>> +        :param comments: a {revision: comment} dict, as returned by get_comments()
>> +        """
>> +        def count_revision_comments(revision_comments):
>> +            return len([cm for cm in revision_comments if cm.text])
>> +        return {raw_id: count_revision_comments(revision_comments) for raw_id, revision_comments in comments.iteritems()}
>> +
>>      def statuses(self, revisions):
>>          """
>>          Returns statuses for this repository.
>> diff --git a/kallithea/templates/changelog/changelog.html b/kallithea/templates/changelog/changelog.html
>> --- a/kallithea/templates/changelog/changelog.html
>> +++ b/kallithea/templates/changelog/changelog.html
>> @@ -120,11 +120,11 @@
>>                              <div class="log-container">
>>                                  <div class="message" id="C-${cs.raw_id}">${h.urlify_commit(cs.message, c.repo_name,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}</div>
>>                                  <div class="extra-container">
>> -                                    %if c.comments.get(cs.raw_id):
>> +                                    %if c.comment_counts.get(cs.raw_id, 0):
>>                                          <div class="comments-container">
>>                                              <div class="comments-cnt" title="${_('Changeset has comments')}">
>>                                                  <a href="${c.comments[cs.raw_id][0].url()}">
>> -                                                    ${len(c.comments[cs.raw_id])}
>> +                                                    ${c.comment_counts.get(cs.raw_id, 0)}
>>                                                      <i class="icon-comment-discussion"></i>
>>                                                  </a>
>>                                              </div>
>> diff --git a/kallithea/templates/changelog/changelog_summary_data.html b/kallithea/templates/changelog/changelog_summary_data.html
>> --- a/kallithea/templates/changelog/changelog_summary_data.html
>> +++ b/kallithea/templates/changelog/changelog_summary_data.html
>> @@ -31,11 +31,11 @@
>>              </div>
>>          </td>
>>          <td class="compact">
>> -              %if c.comments.get(cs.raw_id,[]):
>> +              %if c.comment_counts.get(cs.raw_id, 0):
>>                 <div class="comments-container">
>>                     <div title="${('comments')}">
>> -                       <a href="${c.comments[cs.raw_id][0].url()}">
>> -                          <i class="icon-comment"></i>${len(c.comments[cs.raw_id])}
>> +                        <a href="${c.comments[cs.raw_id][0].url()}">
>> +                           <i class="icon-comment"></i>${c.comment_counts.get(cs.raw_id, 0)}
>>                         </a>
>>                     </div>
>>                 </div>
>>
>
> There are other places where comments are counted (wrongly), I think
> it would be great to fix them all. For example:
> templates/compare/compare_cs.html which is used from pullrequest_show.html.
>
> /Thomas

Thank you for the comment. You are right. I just sent V3 of this patch
which addresses that. I did not find any other places where comment
counts are shown (other than the one you just mention), except for the
changeset page, which shows both inline and general comments. I think
that should be addressed on a separate patch.

Cheers,

Angel


More information about the kallithea-general mailing list