GitLab's commit diff retrieval/rendering is bonkers
Creating this issue mostly so I can leave notes for myself.
Currently GitLab's commit diff rendering works as follows:
- Get the commit we're displaying
- Get all the diffs from this commit using a
Gitlab::Git::DiffCollection
- Wrap every diff in 15 layers of indirection
- For every diff call out to
repository.blob_at
to get the blob, despite the diff already containing all information we want to display - For every diff call out to
repository.comimt
to get a Commit object, despite it most likely being possible to just get this data when we get the diff collection - Verify the size of the blob so we're not rendering too large blobs. However at this point the blob (at least a large chunk of it) is already loaded into memory.
To work around this we'd have to adjust the various views so they can operate on a Gitlab::Diff::File
instance instead of requiring Blob
and Commit
instances. Alternative we can try to create a Blob
based on an existing Gitlab::Diff::File
. The latter is probably the easiest solution. Care should be taken that expanding collapsed diffs and viewing raw diffs will still work.