picky 3.6.2 → 3.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/backends/redis.rb +54 -24
- metadata +27 -27
data/lib/picky/backends/redis.rb
CHANGED
@@ -88,26 +88,44 @@ module Picky
|
|
88
88
|
#
|
89
89
|
# Note: We use the amount and offset hints to speed Redis up.
|
90
90
|
#
|
91
|
-
|
92
|
-
#
|
93
|
-
#
|
94
|
-
|
95
|
-
# local
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
#
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
#
|
109
|
-
|
110
|
-
|
91
|
+
def ids combinations, amount, offset
|
92
|
+
# Just checked once on the first call.
|
93
|
+
#
|
94
|
+
if redis_with_scripting?
|
95
|
+
@@script = "local intersected = redis.call('zinterstore', ARGV[1], #(KEYS), unpack(KEYS)); if intersected == 0 then redis.call('del', ARGV[1]); return {}; end local results = redis.call('zrange', ARGV[1], tonumber(ARGV[2]), tonumber(ARGV[3])); redis.call('del', ARGV[1]); return results;"
|
96
|
+
|
97
|
+
require 'digest/sha1'
|
98
|
+
@@sent_once = nil
|
99
|
+
|
100
|
+
# Scripting version of #ids.
|
101
|
+
#
|
102
|
+
def ids combinations, amount, offset
|
103
|
+
identifiers = combinations.inject([]) do |identifiers, combination|
|
104
|
+
identifiers << "#{combination.identifier}"
|
105
|
+
end
|
106
|
+
|
107
|
+
# Assume it's using EVALSHA.
|
108
|
+
#
|
109
|
+
begin
|
110
|
+
client.evalsha @@sent_once,
|
111
|
+
identifiers.size,
|
112
|
+
*identifiers,
|
113
|
+
generate_intermediate_result_id,
|
114
|
+
offset,
|
115
|
+
(offset + amount)
|
116
|
+
rescue RuntimeError => e
|
117
|
+
# Make the server have a SHA-1 for the script.
|
118
|
+
#
|
119
|
+
@@sent_once = Digest::SHA1.hexdigest @@script
|
120
|
+
client.eval @@script,
|
121
|
+
identifiers.size,
|
122
|
+
*identifiers,
|
123
|
+
generate_intermediate_result_id,
|
124
|
+
offset,
|
125
|
+
(offset + amount)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
else
|
111
129
|
# Non-Scripting version of #ids.
|
112
130
|
#
|
113
131
|
def ids combinations, amount, offset
|
@@ -119,7 +137,14 @@ module Picky
|
|
119
137
|
|
120
138
|
# Intersect and store.
|
121
139
|
#
|
122
|
-
client.zinterstore result_id, identifiers
|
140
|
+
intersected = client.zinterstore result_id, identifiers
|
141
|
+
|
142
|
+
# Return clean and early if there has been no intersection.
|
143
|
+
#
|
144
|
+
if intersected.zero?
|
145
|
+
client.del result_id
|
146
|
+
return []
|
147
|
+
end
|
123
148
|
|
124
149
|
# Get the stored result.
|
125
150
|
#
|
@@ -127,14 +152,19 @@ module Picky
|
|
127
152
|
|
128
153
|
# Delete the stored result as it was only for temporary purposes.
|
129
154
|
#
|
130
|
-
# Note: I could also not delete it, but that
|
155
|
+
# Note: I could also not delete it, but that
|
156
|
+
# would not be clean at all.
|
131
157
|
#
|
132
158
|
client.del result_id
|
133
159
|
|
134
160
|
results
|
135
161
|
end
|
136
|
-
|
137
|
-
|
162
|
+
end
|
163
|
+
|
164
|
+
# Call the newly installed version.
|
165
|
+
#
|
166
|
+
ids combinations, amount, offset
|
167
|
+
end
|
138
168
|
|
139
169
|
# Generate a multiple host/process safe result id.
|
140
170
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70145176900860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70145176900860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: picky-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70145176900360 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 3.6.
|
32
|
+
version: 3.6.3
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70145176900360
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70145176899920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70145176899920
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack_fast_escape
|
49
|
-
requirement: &
|
49
|
+
requirement: &70145176899440 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70145176899440
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: text
|
60
|
-
requirement: &
|
60
|
+
requirement: &70145176898940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70145176898940
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yajl-ruby
|
71
|
-
requirement: &
|
71
|
+
requirement: &70145176898460 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70145176898460
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activesupport
|
82
|
-
requirement: &
|
82
|
+
requirement: &70145176912720 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '3.0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70145176912720
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: activerecord
|
93
|
-
requirement: &
|
93
|
+
requirement: &70145176910220 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '3.0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70145176910220
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: unicorn
|
104
|
-
requirement: &
|
104
|
+
requirement: &70145176909100 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70145176909100
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sinatra
|
115
|
-
requirement: &
|
115
|
+
requirement: &70145176908040 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70145176908040
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: redis
|
126
|
-
requirement: &
|
126
|
+
requirement: &70145176907360 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70145176907360
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: mysql
|
137
|
-
requirement: &
|
137
|
+
requirement: &70145176906940 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,7 +142,7 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70145176906940
|
146
146
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
147
147
|
email: florian.hanke+picky@gmail.com
|
148
148
|
executables:
|