Persist diff statistics on `merge_request_diff_files`

Why

Currently in order to present each file statistics (added lines, removed lines) for a Merge Request we parse every diff line, which loads up a bunch of Gitlab::Diff::Line into memory. Turns out we could stop parsing lines and leave heavy-lifting to git diff --numstat and persist it:

› git diff --numstat master
1       0       .gitattributes
3       0       Gemfile
2       1       Gemfile.lock
1       0       app/controllers/concerns/issues_action.rb
10      0       app/controllers/profiles_controller.rb
6       0       app/finders/issues_finder.rb
26      0       app/helpers/calendar_helper.rb
7       6       app/models/issue.rb
6       0       app/models/user.rb
3       1       app/views/dashboard/issues.html.haml
3       0       app/views/dashboard/issues.ics.haml
18      0       app/views/profiles/personal_access_tokens/index.html.haml
5       0       changelogs/unreleased/44184-issues_ical_feed.yml
1       0       config/routes/profile.rb
19      0       db/migrate/20180315141051_add_calendar_token_to_users.rb
3       1       db/schema.rb
4       0       doc/user/project/issues/due_dates.md
1       1       lib/gitlab/auth/request_authenticator.rb
12      4       lib/gitlab/auth/user_auth_finders.rb
4       0       spec/factories/users.rb
1       1       spec/features/dashboard/issues_filter_spec.rb
48      0       spec/features/ics/dashboard_issues_spec.rb
14      0       spec/features/issues_spec.rb
18      0       spec/features/profile_spec.rb
40      0       spec/helpers/calendar_helper_spec.rb
5       5       spec/lib/gitlab/auth/request_authenticator_spec.rb
19      7       spec/lib/gitlab/auth/user_auth_finders_spec.rb
10      0       spec/models/user_spec.rb
4       0       spec/routing/routing_spec.rb

What (proposal)

Today we persist MR file diffs into merge_request_diff_files. As mentioned on https://gitlab.com/gitlab-org/gitlab-ce/issues/36051#note_50276332, having additions and deletions "cached" there sounds a reasonable approach.

Possibly we'd need to send a RPC to Gitaly which would receive the reference and return something like:

[
  {
    filename: ".gitattributes",
    additions: 1,
    deletions: 0
  },
  ...
]

The persistence w'd happens upon merge_request_diff_files creation.

Edited Mar 29, 2018 by Oswaldo Ferreira
Assignee Loading
Time tracking Loading