Add to the types of diff line counts we cache.
Review Request #5493 — Created Feb. 18, 2014 and submitted — Latest diff uploaded
Early in 2.0, we began caching the raw insert/delete counts from the
patch file onFileDiffData
. 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 forFileDiffData
.The values we were storing were also a bit expensive to get, since we
had to fetch aDiffFileData
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 theFileDiff
'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.