elastic_record 4.1.1 → 4.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/elastic_record.gemspec +1 -1
- data/lib/elastic_record.rb +1 -0
- data/lib/elastic_record/model.rb +1 -0
- data/lib/elastic_record/name_cache.rb +23 -0
- data/test/elastic_record/name_cache_test.rb +16 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd6f75dec0ea4b1919142bb0ba494194b7311bc8
|
4
|
+
data.tar.gz: 2023aa88262eea919d945492810a9045851a7fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f64bc4220954f757d8779f811ec7f09aa7f75e8b4fb7464f4205dca7aefa054424d42069cb68c68e0b0a2998e842525bfbd6db95ed4ca4a9a9f464537a9240fa
|
7
|
+
data.tar.gz: d49988d87eb175d619969f51aa535749252582b369f78581bddd85b8167441db1603860b69a94200cc206117981118673da5121932704a657eb5617330e48ec6
|
data/elastic_record.gemspec
CHANGED
data/lib/elastic_record.rb
CHANGED
@@ -12,6 +12,7 @@ module ElasticRecord
|
|
12
12
|
autoload :JSON, 'elastic_record/json'
|
13
13
|
autoload :Lucene, 'elastic_record/lucene'
|
14
14
|
autoload :Model, 'elastic_record/model'
|
15
|
+
autoload :NameCache, 'elastic_record/name_cache'
|
15
16
|
autoload :PercolatorModel, 'elastic_record/percolator_model'
|
16
17
|
autoload :Relation, 'elastic_record/relation'
|
17
18
|
autoload :Searching, 'elastic_record/searching'
|
data/lib/elastic_record/model.rb
CHANGED
@@ -6,6 +6,7 @@ module ElasticRecord
|
|
6
6
|
extend ClassMethods
|
7
7
|
include Callbacks
|
8
8
|
include AsDocument
|
9
|
+
include NameCache
|
9
10
|
|
10
11
|
class_attribute :elastic_connection
|
11
12
|
self.elastic_connection = ElasticRecord::Connection.new(ElasticRecord::Config.servers, ElasticRecord::Config.connection_options)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ElasticRecord
|
2
|
+
module NameCache
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
class_attribute :cached_index_name
|
7
|
+
class_attribute :index_name_cache_time
|
8
|
+
self.index_name_cache_time = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
class_methods do
|
12
|
+
def current_index_name
|
13
|
+
if (Time.now - index_name_cache_time) < 60
|
14
|
+
cached_index_name
|
15
|
+
else
|
16
|
+
self.index_name_cache_time = Time.now
|
17
|
+
aliased_names = elastic_connection.json_get("/_alias/#{elastic_index.alias_name}").keys
|
18
|
+
self.cached_index_name = aliased_names.first
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ElasticRecord::NameCacheTest < MiniTest::Test
|
4
|
+
class Felon
|
5
|
+
include TestModel
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_index_name
|
9
|
+
begin
|
10
|
+
Felon.elastic_index.create_and_deploy("felons_datestamp")
|
11
|
+
assert_equal "felons_datestamp", Felon.current_index_name
|
12
|
+
ensure
|
13
|
+
Felon.elastic_index.delete("felons_datestamp")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infogroup
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/elastic_record/log_subscriber.rb
|
72
72
|
- lib/elastic_record/lucene.rb
|
73
73
|
- lib/elastic_record/model.rb
|
74
|
+
- lib/elastic_record/name_cache.rb
|
74
75
|
- lib/elastic_record/percolator_model.rb
|
75
76
|
- lib/elastic_record/railtie.rb
|
76
77
|
- lib/elastic_record/railties/controller_runtime.rb
|
@@ -152,6 +153,7 @@ files:
|
|
152
153
|
- test/elastic_record/log_subscriber_test.rb
|
153
154
|
- test/elastic_record/lucene_test.rb
|
154
155
|
- test/elastic_record/model_test.rb
|
156
|
+
- test/elastic_record/name_cache_test.rb
|
155
157
|
- test/elastic_record/percolator_model_test.rb
|
156
158
|
- test/elastic_record/railties/controller_runtime_test.rb
|
157
159
|
- test/elastic_record/relation/batches_test.rb
|
@@ -183,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
185
|
version: 1.8.11
|
184
186
|
requirements: []
|
185
187
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.6.
|
188
|
+
rubygems_version: 2.6.13
|
187
189
|
signing_key:
|
188
190
|
specification_version: 4
|
189
191
|
summary: An Elasticsearch querying ORM
|