Commit 4d3c8c2e authored by Dylan Griffith's avatar Dylan Griffith

Monkey patch ES gem by re-opening module

The reason to do this instead of the prepend approach is that this
module is included in other places and as such prepending over that
method later seems to have no effect.
parent c586d248
...@@ -10,7 +10,6 @@ Gitlab.ee do ...@@ -10,7 +10,6 @@ Gitlab.ee do
### Monkey patches ### Monkey patches
Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records
Elasticsearch::Model::Response::Results.prepend GemExtensions::Elasticsearch::Model::Response::Results
Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records
Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods
Elasticsearch::Model::Adapter::ActiveRecord::Importing.prepend GemExtensions::Elasticsearch::Model::Adapter::ActiveRecord::Importing Elasticsearch::Model::Adapter::ActiveRecord::Importing.prepend GemExtensions::Elasticsearch::Model::Adapter::ActiveRecord::Importing
...@@ -19,6 +18,32 @@ Gitlab.ee do ...@@ -19,6 +18,32 @@ Gitlab.ee do
Elasticsearch::Model::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client Elasticsearch::Model::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model.singleton_class.prepend GemExtensions::Elasticsearch::Model::Client Elasticsearch::Model.singleton_class.prepend GemExtensions::Elasticsearch::Model::Client
# This monkey patch cannot be handled by prepend like the above since this
# module is included into other classes.
module Elasticsearch
module Model
module Response
module Base
if Gem::Version.new(Elasticsearch::Model::VERSION) >= Gem::Version.new('7.0.0')
raise "elasticsearch-model was upgraded, please remove this monkey patch in #{__FILE__}"
end
# Handle ES7 API where total is returned as an object. This
# change is taken from the V7 gem
# https://github.com/elastic/elasticsearch-rails/commit/9c40f630e1b549f0b7889fe33dcd826b485af6fc
# and can be removed when we upgrade the gem to V7
def total
if response.response['hits']['total'].respond_to?(:keys)
response.response['hits']['total']['value']
else
response.response['hits']['total']
end
end
end
end
end
end
### Modified from elasticsearch-model/lib/elasticsearch/model.rb ### Modified from elasticsearch-model/lib/elasticsearch/model.rb
[ [
......
# frozen_string_literal: true
module GemExtensions
module Elasticsearch
module Model
module Response
module Results
# Handle ES7 API where total is returned as an object. This
# change is taken from the V7 gem
# https://github.com/elastic/elasticsearch-rails/commit/9c40f630e1b549f0b7889fe33dcd826b485af6fc
# and can be removed when we upgrade the gem to V7
def total
if response.response['hits']['total'].respond_to?(:keys)
response.response['hits']['total']['value']
else
response.response['hits']['total']
end
end
end
end
end
end
end
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