Commit d111b146 authored by Robert Speicher's avatar Robert Speicher

Merge branch '835-find-commits-by-message-with-elastic-fix' into 'master'

Strip out `nil`s in the Array of Commit objects returned from `find_commits_by_message_with_elastic`

Closes #835

See merge request !1430
parents dc630cd3 0bd76cc6
......@@ -31,7 +31,7 @@ module Elastic
commits = response.map do |result|
commit result["_source"]["commit"]["sha"]
end
end.compact
# Before "map" we had a paginated array so we need to recover it
offset = per_page * ((page || 1) - 1)
......@@ -49,11 +49,16 @@ module Elastic
options: options
)[:commits][:results]
# Avoid one SELECT per result by loading all projects into a hash
project_ids = response.map {|result| result["_source"]["commit"]["rid"] }.uniq
projects = Project.where(id: project_ids).index_by(&:id)
commits = response.map do |result|
sha = result["_source"]["commit"]["sha"]
project = Project.find(result["_source"]["commit"]["rid"])
project.commit(sha)
end
project_id = result["_source"]["commit"]["rid"]
projects[project_id].try(:commit, sha)
end.compact
# Before "map" we had a paginated array so we need to recover it
offset = per_page * ((page || 1) - 1)
......
---
title: Fix 500 errors caused by elasticsearch results referencing garbage-collected commits
merge_request: 1430
author:
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment