title: In a Bugzilla extension, how does one detect a new comment being added?
body: <p>Which hook does one need to hook into to determine when a new comment is being added to a bug?</p>
  
  <p>My use case is that whenever a comment is being added I need to process all comments, and perform some action based on that. However, this action is “expensive”, so I don't want to perform the action unless a comment has really been added.</p>
  
  <p>The only way that I have found so far to determine this is to hook into <code>object_end_of_update</code> with the code:</p>
  
  <pre class="lang-perl prettyprint-override"><code>sub object_end_of_update {
    my ($self, $args) = @_;
  
    my ($object, $old_object, $changes) = @$args{qw(object old_object changes)};
    print STDERR "--- Object Type: " . ref $object;
    if ($object-&gt;isa('Bugzilla::Bug')) {
      # Load comments on the old object here, otherwise by the time we get
      # to bug_end_of_update it is too late, and we cannot determine if a
      # new comment has been added or not.
      $old_object-&gt;comments({order=&gt;'oldest_to_newest'});
    }
  }
  </code></pre>
  
  <p>and then to hook into <code>bug_end_of_update</code>, whereupon I can do something like:</p>
  
  <pre class="lang-perl prettyprint-override"><code>sub bug_end_of_update {
    my ($self, $args) = @_;
  
    my ($bug, $old_bug, $timestamp, $changes) = @$args{qw(bug old_bug timestamp changes)};
    # Note that this will only work if the old comments have already been
    # loaded in object_end_of_update, otherwise when we get the old comments
    # here, it just goes to the DB, and gets all of the comments, including
    # the new one, if there is one.
    my $oldComments = $old_bug-&gt;comments({order=&gt;'oldest_to_newest'});
    my $newComments = $bug-&gt;comments({order=&gt;'oldest_to_newest'});
    if (scalar(@$newComments) &gt; scalar(@$oldComments)) {
      # If we added a new comment, then perform processing.
      do_slow_action($bug);
    }
  }
  </code></pre>
  
  <p>However, this feels fragile, and even if it isn't, is definitely not clear code.</p>
  
  <p>What is the correct way to determine that a comment has been added to a bugzilla bug?</p>