From cc3141625e4c87387259c38e4ab5f56820621768 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Fri, 14 Oct 2016 01:58:37 +0000 Subject: Bug 1309487 - include longdescs.count in result for /rest/bug --- Bugzilla/Bug.pm | 12 ++++++++++++ Bugzilla/WebService/Bug.pm | 4 ++++ docs/en/rst/api/core/v1/bug.rst | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 77d2e126a..69734e6c0 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -265,6 +265,7 @@ use constant FIELD_MAP => { is_cc_accessible => 'cclist_accessible', is_creator_accessible => 'reporter_accessible', last_change_time => 'delta_ts', + comment_count => 'longdescs.count', platform => 'rep_platform', severity => 'bug_severity', status => 'bug_status', @@ -3661,6 +3662,17 @@ sub comments { return \@comments; } +sub comment_count { + my ($self) = @_; + return $self->{comment_count} if $self->{comment_count}; + my $dbh = Bugzilla->dbh; + return $self->{comment_count} = + $dbh->selectrow_array('SELECT COUNT(longdescs.comment_id) + FROM longdescs + WHERE longdescs.bug_id = ?', + undef, $self->id); +} + # This is needed by xt/search.t. sub percentage_complete { my $self = shift; diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 20a21147d..bbab65137 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -1476,6 +1476,10 @@ sub _bug_to_hash { = [ map { $self->_user_to_hash($_, $params, undef, 'mentors') } @{ $bug->mentors } ]; } + if (filter_wants $params, 'comment_count') { + $item{'comment_count'} = $self->type('int', $bug->comment_count); + } + return \%item; } diff --git a/docs/en/rst/api/core/v1/bug.rst b/docs/en/rst/api/core/v1/bug.rst index 137f83256..3c7605527 100644 --- a/docs/en/rst/api/core/v1/bug.rst +++ b/docs/en/rst/api/core/v1/bug.rst @@ -115,7 +115,8 @@ name type description "email": "namachi@netscape.com" }, "cf_free_text": "", - "blocks": [] + "blocks": [], + "comment_count": 12 } ] } @@ -185,6 +186,7 @@ is_creator_accessible boolean If ``true``, this bug can be accessed by the member of the groups the bug is restricted to. keywords array Each keyword that is on this bug. last_change_time datetime When the bug was last changed. +comment_count int Number of comments associated with the bug. op_sys string The name of the operating system that the bug was filed against. platform string The name of the platform (hardware) that the bug -- cgit v1.2.3-24-g4f1b