Class: Repositories::TreeFinder
- Inherits:
-
Object
- Object
- Repositories::TreeFinder
- Defined in:
- app/finders/repositories/tree_finder.rb
Constant Summary collapse
- CommitMissingError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#next_cursor ⇒ Object
readonly
Returns the value of attribute next_cursor.
Instance Method Summary collapse
- #commit_exists? ⇒ Boolean
- #execute(gitaly_pagination: false) ⇒ Object
-
#initialize(project, params = {}) ⇒ TreeFinder
constructor
A new instance of TreeFinder.
- #total ⇒ Object
Constructor Details
#initialize(project, params = {}) ⇒ TreeFinder
Returns a new instance of TreeFinder.
9 10 11 12 13 14 |
# File 'app/finders/repositories/tree_finder.rb', line 9 def initialize(project, params = {}) @project = project @repository = project.repository @params = params @next_cursor = nil end |
Instance Attribute Details
#next_cursor ⇒ Object (readonly)
Returns the value of attribute next_cursor.
7 8 9 |
# File 'app/finders/repositories/tree_finder.rb', line 7 def next_cursor @next_cursor end |
Instance Method Details
#commit_exists? ⇒ Boolean
37 38 39 |
# File 'app/finders/repositories/tree_finder.rb', line 37 def commit_exists? commit.present? end |
#execute(gitaly_pagination: false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/finders/repositories/tree_finder.rb', line 16 def execute(gitaly_pagination: false) raise CommitMissingError unless commit_exists? request_params = { recursive: recursive, rescue_not_found: rescue_not_found } request_params[:pagination_params] = pagination_params if gitaly_pagination tree = repository.tree(commit.id, path, **request_params) @next_cursor = tree.cursor&.next_cursor if gitaly_pagination tree.sorted_entries end |
#total ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/finders/repositories/tree_finder.rb', line 29 def total # This is inefficient and we'll look at replacing this implementation cache_key = [project, repository.commit, :tree_size, commit.id, path, recursive] Gitlab::Cache.fetch_once(cache_key) do repository.tree(commit.id, path, recursive: recursive).entries.size end end |