Class: Gitlab::Diff::FileCollection::Commit
- Defined in:
- lib/gitlab/diff/file_collection/commit.rb
Constant Summary collapse
- DEFAULT_LIMIT_HIGHLIGHT_COLLECTION =
The maximum time allowed to highlight all the files in a commit (in seconds).
10
Instance Attribute Summary
Attributes inherited from Base
#diff_options, #diff_refs, #diffable, #fallback_diff_refs, #project
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#initialize(commit, diff_options:) ⇒ Commit
constructor
A new instance of Commit.
-
#with_highlights_preloaded ⇒ Object
We need to preload the diffs highlighting to track every diff file and the time that they take to format.
Methods inherited from Base
#clear_cache, default_options, #diff_file_paths, #diff_file_with_new_path, #diff_file_with_old_path, #diff_files, #diff_paths, #diffs, max_blob_size, #overflow?, #pagination_data, #raw_diff_files, #unfold_diff_files, #write_cache
Constructor Details
#initialize(commit, diff_options:) ⇒ Commit
Returns a new instance of Commit.
10 11 12 13 14 15 |
# File 'lib/gitlab/diff/file_collection/commit.rb', line 10 def initialize(commit, diff_options:) super(commit, project: commit.project, diff_options: , diff_refs: commit.diff_refs) end |
Instance Method Details
#cache_key ⇒ Object
40 41 42 |
# File 'lib/gitlab/diff/file_collection/commit.rb', line 40 def cache_key ['commit', @diffable.id] end |
#with_highlights_preloaded ⇒ Object
We need to preload the diffs highlighting to track every diff file and the time that they take to format. If the highlight rich collection limit is reached, then we render the rest of diff files as plain text to avoid saturating the resources.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitlab/diff/file_collection/commit.rb', line 21 def with_highlights_preloaded @with_highlights_preloaded ||= begin start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) diff_files.each do |diff_file| current_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) use_plain_highlight = current_time - start_time >= DEFAULT_LIMIT_HIGHLIGHT_COLLECTION diff_file.highlighted_diff_lines = Gitlab::Diff::Highlight.new( diff_file, repository: diff_file.repository, plain: use_plain_highlight ).highlight end self end end |