diff options
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index ab8782ed87f..5fdd4551982 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -45,7 +45,7 @@ class Snippet < ApplicationRecord has_many :notes, as: :noteable, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :user_mentions, class_name: "SnippetUserMention", dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent has_one :snippet_repository, inverse_of: :snippet - has_many :repository_storage_moves, class_name: 'SnippetRepositoryStorageMove', inverse_of: :container + has_many :repository_storage_moves, class_name: 'Snippets::RepositoryStorageMove', inverse_of: :container # We need to add the `dependent` in order to call the after_destroy callback has_one :statistics, class_name: 'SnippetStatistics', dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent @@ -82,6 +82,7 @@ class Snippet < ApplicationRecord scope :fresh, -> { order("created_at DESC") } scope :inc_author, -> { includes(:author) } scope :inc_relations_for_view, -> { includes(author: :status) } + scope :inc_statistics, -> { includes(:statistics) } scope :with_statistics, -> { joins(:statistics) } scope :inc_projects_namespace_route, -> { includes(project: [:route, :namespace]) } @@ -216,8 +217,10 @@ class Snippet < ApplicationRecord def blobs return [] unless repository_exists? - branch = default_branch - list_files(branch).map { |file| Blob.lazy(repository, branch, file) } + files = list_files(default_branch) + items = files.map { |file| [default_branch, file] } + + repository.blobs_at(items).compact end def hook_attrs |