Enforce a sort order when collecting prefetched files for a diff.
Enforce a sort order when collecting prefetched files for a diff.

When collecting `FileDiff`s in `DiffSet.per_commit_files()` and
`DiffSet.cumulative_files()`, it was possible to get files that weren't
in an expected order. These could come from the database in index order
and not insertion order. While this generally wouldn't be a huge
problem for general lookups of files (and wasn't a problem for all
database setups), it could lead to out-of-order raw diffs, which could
easily break anything trying to access them.

This is an edge case for sure, and one where we don't have a good
reproduction case. It seems to be dependent on the database.

We now explicitly force an order based on the primary key. Currently,
we're only enforcing them in these properties, and not as the default
sort order for the model, in order to avoid any unintentional side
effects.

Testing Done:
Unit tests pass.

Tested in production with a customer who encountered this problem. We
verified the fix.

Reviewed at https://reviews.reviewboard.org/r/11736/

chipx86/reviewboard,chipx86/reviewboard,reviewboard/reviewboard,reviewboard/reviewboard,chipx86/reviewboard,chipx86/reviewboard,reviewboard/reviewboard,reviewboard/reviewboard