summaryrefslogtreecommitdiff
path: root/lib/gitlab/gitaly_client
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2019-01-02 15:39:47 -0800
committerJohn Cai <jcai@gitlab.com>2019-02-06 20:32:53 -0800
commit04b9de85a8355a9e9f4827fcd608c3ea2bcd7df0 (patch)
tree3f30358e667dc6b71a2cca3b351e43f5335cc897 /lib/gitlab/gitaly_client
parent684a1a17674d92682c9d91c4e944e1a31b0bcda4 (diff)
downloadgitlab-ce-04b9de85a8355a9e9f4827fcd608c3ea2bcd7df0.tar.gz
Modifying gitaly search files client to add chunking support
updates gitaly proto to 1.7.0, modifies the search files gitaly client call to use the new chunked_response flag in the rpc request, and stitch the responses together. maintains backwards compatibility with older gitaly servers.
Diffstat (limited to 'lib/gitlab/gitaly_client')
-rw-r--r--lib/gitlab/gitaly_client/repository_service.rb33
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb
index 8a1abfbf874..a7e20d9429e 100644
--- a/lib/gitlab/gitaly_client/repository_service.rb
+++ b/lib/gitlab/gitaly_client/repository_service.rb
@@ -324,13 +324,40 @@ module Gitlab
GitalyClient.call(@storage, :repository_service, :search_files_by_name, request, timeout: GitalyClient.fast_timeout).flat_map(&:files)
end
- def search_files_by_content(ref, query)
- request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query)
- GitalyClient.call(@storage, :repository_service, :search_files_by_content, request).flat_map(&:matches)
+ def search_files_by_content(ref, query, chunked_response: true)
+ request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query, chunked_response: chunked_response)
+ response = GitalyClient.call(@storage, :repository_service, :search_files_by_content, request)
+
+ search_results_from_response(response)
end
private
+ def search_results_from_response(gitaly_response)
+ matches = []
+ current_match = +""
+
+ gitaly_response.each do |message|
+ next if message.nil?
+
+ # Old client will ignore :chunked_response flag
+ # and return messages with `matches` key.
+ # This code path will be removed post 12.0 release
+ if message.matches.any?
+ matches += message.matches
+ else
+ current_match << message.match_data
+
+ if message.end_of_match
+ matches << current_match
+ current_match = +""
+ end
+ end
+ end
+
+ matches
+ end
+
def gitaly_fetch_stream_to_file(save_path, rpc_name, request_class, timeout)
request = request_class.new(repository: @gitaly_repo)
response = GitalyClient.call(