Add to the types of diff line counts we cache.

Review Request #5493 — Created Feb. 18, 2014 and submitted

Information

Review Board
master
4e4f82b...

Reviewers

Early in 2.0, we began caching the raw insert/delete counts from the
patch file on FileDiffData. We didn't compute the displayed
insert/delete/replace counts because they couldn't be computed at will
without going through a diff generation cycle. They're also more
display-specific, as they depend on the particular diff renderer used,
so they're not a good fit for FileDiffData.

The values we were storing were also a bit expensive to get, since we
had to fetch a DiffFileData for each one. That meant that on the
dashboard, adding the Diff Size column would end up doing 1 query per
row.

Those counts are useful, even if we can't always rely on having them.
We also want all counts closer to avoid the fetches. This change
calculates them at render time and stores them on the FileDiff's
extra_data.

In particular, the following are now stored:

  • raw_insert_count
  • raw_delete_count
  • insert_count
  • delete_count
  • replace_count
  • equal_count
  • total_line_count

In the new terminology, the insert/delete counts are for the processed
(rendered) counts, while the raw versions are from the patch.

FileDiff's set_line_counts has been updated to take all those line
counts. Each are optional.

There's also now a get_line_counts that returns all the counts that are
available, and a DiffSet.get_total_line_counts that computes the counts
for all files. For these, there's a guarantee that insert_count,
delete_count, raw_insert_count, and raw_delete_count will be returned.
The rest depend on whether they've been set before.

If the diff hasn't been rendered yet, the non-raw insert/delete counts
will be set to the raw versions. This helps ensure we have at least
something. Callers using those will get the processed versions after
the first render.

Unit tests pass.

Checked the counts after the first call to get_line_counts (without
re-rendering the diff) and saw that only the raw/non-raw insert/delete
counts were there, and that they were the same value.

Rendered a diff and checked again. Saw all the other counts filled in,
and saw that the non-raw insert/delete counts were no longer matching
the raw ones.

Added the Diff Size column to my datagrid and saw those counts.

Checked the codebase for any and all references to the old properties
that were removed. Didn't see any left.

Description From Last Updated

It might be interesting to use the real insert/replace/delete counts if they're available.

daviddavid

Guaranteed to have value?

daviddavid
david
  1. 
      
  2. reviewboard/datagrids/columns.py (Diff revision 1)
     
     
     
    Show all issues

    It might be interesting to use the real insert/replace/delete counts if they're available.

    1. I'd like to do that as well. Maybe use the complexity icon. I don't want to do anything with this column as part of this change, though, since a redesign of the content is unrelated to this change.

  3. reviewboard/diffviewer/models.py (Diff revision 1)
     
     
    Show all issues

    Guaranteed to have value?

  4. 
      
chipx86
david
  1. Ship It!

  2. 
      
chipx86
Review request changed
Status:
Completed