algoliasearch 1.12.2 → 1.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +3 -0
- data/lib/algolia/client.rb +26 -3
- data/lib/algolia/version.rb +1 -1
- data/spec/client_spec.rb +9 -0
- data/spec/mock_spec.rb +4 -1
- data/spec/stub_spec.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4050df50fa8668d5c9c873c8783a195bd575dd6f
|
4
|
+
data.tar.gz: 214b9bc3a0afc498470fe6d21fab6a3893ea138d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d92b856c6c07c952637e11c4108c7057f844bc8a0eab04e53a3aa9a0200124036220e8808db600892d1e63062ea8147210cdd41df33abf8eb3ad07c98d550688
|
7
|
+
data.tar.gz: 534342154bf113bc6f65385c875907f0f90c48c464b73dbfb004372c3d3da57a67d5f3dd66f1c4c03eb97b065b85d371df8c3758cbaf1ff66cc7459a7559527c
|
data/ChangeLog
CHANGED
data/lib/algolia/client.rb
CHANGED
@@ -41,6 +41,11 @@ module Algolia
|
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
44
|
+
def destroy
|
45
|
+
Thread.current["algolia_search_hosts_#{application_id}"] = nil
|
46
|
+
Thread.current["algolia_hosts_#{application_id}"] = nil
|
47
|
+
end
|
48
|
+
|
44
49
|
#
|
45
50
|
# Initialize a new index
|
46
51
|
#
|
@@ -338,6 +343,10 @@ module Algolia
|
|
338
343
|
send_timeout += 10 if i == 2
|
339
344
|
receive_timeout += 10 if i == 2
|
340
345
|
|
346
|
+
thread_index_key = type != :write ? "algolia_search_host_index_#{application_id}" : "algolia_host_index_#{application_id}"
|
347
|
+
Thread.current[thread_index_key] = host[:index]
|
348
|
+
host[:last_call] = Time.now.to_i
|
349
|
+
|
341
350
|
host[:session].connect_timeout = connect_timeout
|
342
351
|
host[:session].send_timeout = send_timeout
|
343
352
|
host[:session].receive_timeout = receive_timeout
|
@@ -374,16 +383,29 @@ module Algolia
|
|
374
383
|
|
375
384
|
# This method returns a thread-local array of sessions
|
376
385
|
def thread_local_hosts(read)
|
377
|
-
|
386
|
+
thread_hosts_key = read ? "algolia_search_hosts_#{application_id}" : "algolia_hosts_#{application_id}"
|
387
|
+
Thread.current[thread_hosts_key] ||= (read ? search_hosts : hosts).each_with_index.map do |host, i|
|
378
388
|
client = HTTPClient.new
|
379
389
|
client.ssl_config.ssl_version = @ssl_version if @ssl && @ssl_version
|
380
390
|
client.transparent_gzip_decompression = true
|
381
391
|
client.ssl_config.add_trust_ca File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'resources', 'ca-bundle.crt'))
|
382
392
|
{
|
393
|
+
:index => i,
|
383
394
|
:base_url => "http#{@ssl ? 's' : ''}://#{host}",
|
384
|
-
:session => client
|
395
|
+
:session => client,
|
396
|
+
:last_call => nil
|
385
397
|
}
|
386
398
|
end
|
399
|
+
hosts = Thread.current[thread_hosts_key]
|
400
|
+
thread_index_key = read ? "algolia_search_host_index_#{application_id}" : "algolia_host_index_#{application_id}"
|
401
|
+
current_host = Thread.current[thread_index_key].to_i # `to_i` to ensure first call is 0
|
402
|
+
if current_host != 0 && hosts[current_host][:last_call].to_i < Time.now.to_i - 60
|
403
|
+
# the current_host is not the first one and we've been using it for less than a minute; continue doing so
|
404
|
+
first = hosts[current_host]
|
405
|
+
[first] + hosts.reject { |h| h[:index] == 0 || h == first } + hosts.select { |h| h[:index] == 0 }
|
406
|
+
else
|
407
|
+
hosts
|
408
|
+
end
|
387
409
|
end
|
388
410
|
|
389
411
|
def perform_request(session, url, method, data)
|
@@ -649,7 +671,8 @@ module Algolia
|
|
649
671
|
|
650
672
|
# Used mostly for testing. Lets you delete the api key global vars.
|
651
673
|
def Algolia.destroy
|
652
|
-
@@client
|
674
|
+
@@client.destroy unless @@client.nil?
|
675
|
+
@@client = nil
|
653
676
|
self
|
654
677
|
end
|
655
678
|
|
data/lib/algolia/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -997,6 +997,15 @@ describe 'Client' do
|
|
997
997
|
@client.list_indexes # fallback on the second host after 5 sec (connection timeout)
|
998
998
|
expect(start_time.to_i + 5).to be <= Time.now.to_i + 1
|
999
999
|
end
|
1000
|
+
|
1001
|
+
it "should re-use the working (2nd) host after the 1st one failed" do
|
1002
|
+
start_time = Time.now
|
1003
|
+
@client.list_indexes # fallback on the second host after 5 sec (connection timeout)
|
1004
|
+
expect(start_time.to_i + 5).to be <= Time.now.to_i + 1
|
1005
|
+
start_time = Time.now
|
1006
|
+
@client.list_indexes # re-use the 2nd one
|
1007
|
+
expect(start_time.to_i).to be <= Time.now.to_i + 1
|
1008
|
+
end
|
1000
1009
|
end
|
1001
1010
|
end
|
1002
1011
|
|
data/spec/mock_spec.rb
CHANGED
@@ -7,7 +7,10 @@ describe 'With a mocked client' do
|
|
7
7
|
|
8
8
|
before(:each) do
|
9
9
|
WebMock.enable!
|
10
|
-
|
10
|
+
# reset session objects
|
11
|
+
app_id = Algolia.client.application_id
|
12
|
+
Thread.current["algolia_hosts_#{app_id}"] = nil
|
13
|
+
Thread.current["algolia_search_hosts_#{app_id}"] = nil
|
11
14
|
end
|
12
15
|
|
13
16
|
it "should add a simple object" do
|
data/spec/stub_spec.rb
CHANGED
@@ -6,7 +6,10 @@ describe 'With a rate limited client' do
|
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
WebMock.enable!
|
9
|
-
|
9
|
+
# reset session objects
|
10
|
+
app_id = Algolia.client.application_id
|
11
|
+
Thread.current["algolia_hosts_#{app_id}"] = nil
|
12
|
+
Thread.current["algolia_search_hosts_#{app_id}"] = nil
|
10
13
|
end
|
11
14
|
|
12
15
|
it "should pass the right headers" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.12.
|
4
|
+
version: 1.12.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|