relix 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/HISTORY.md +4 -0
- data/lib/relix/core.rb +1 -1
- data/lib/relix/index_set.rb +26 -22
- data/lib/relix/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWRmYWJjZWYxNDM0MmU3OTEzOGE4MzFhODI4Y2RhOWU5ZWY3ZThjMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzJjMDM1MDdmMzM0ZDgyODU1MmMwN2YxZTA0ODgyYzEzOWRiZDYxZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTNmNGVjN2U2ZDc5OTQ1Mzk5ZmZkNjlhYjI3MTI3N2RlZjQwZDMyMTJjOTZk
|
10
|
+
NmEyNWExZmEyNWQ4Y2IyMWIzNWFjMThiMmY1MTgwOWQxMDEzYTk5MTE3MDlj
|
11
|
+
Mjg3Y2E4M2EwYmUwMDM4YTNkMmQ1N2JlNzYyNGY4ODE4M2I1YzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2YwODAwZTRkNDI5MTZkMTlhZGVhYmRiOWNkMWUxMjQ1M2JmMzUwYjg5YzFh
|
14
|
+
ZWI5N2YyMjJjZTQ4MmM3ZGRjMjlhMWQzNjQ2Zjc0NWYyZmQyNzliZjVkOTFi
|
15
|
+
ZTk5MWJiZjAyNjE1ZjJiMTNkYzEyZjNjOWQ4YTQ4NTdmNzFjZDI=
|
data/HISTORY.md
CHANGED
data/lib/relix/core.rb
CHANGED
data/lib/relix/index_set.rb
CHANGED
@@ -2,13 +2,17 @@ module Relix
|
|
2
2
|
class IndexSet
|
3
3
|
attr_accessor :redis
|
4
4
|
attr_reader :klass
|
5
|
-
def initialize(klass,
|
5
|
+
def initialize(klass, redis_source)
|
6
6
|
@klass = klass
|
7
|
-
@
|
7
|
+
@redis_source = redis_source
|
8
8
|
@indexes = Hash.new
|
9
9
|
@keyer = Keyer.default_for(@klass) unless parent
|
10
10
|
end
|
11
11
|
|
12
|
+
def redis
|
13
|
+
@redis ||= @redis_source.redis
|
14
|
+
end
|
15
|
+
|
12
16
|
def primary_key(accessor)
|
13
17
|
@primary_key_index = add_index(:primary_key, accessor)
|
14
18
|
end
|
@@ -57,38 +61,38 @@ module Relix
|
|
57
61
|
yield(query)
|
58
62
|
query.run
|
59
63
|
else
|
60
|
-
primary_key_index.all(
|
64
|
+
primary_key_index.all(redis)
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
def lookup_values(index)
|
65
|
-
self[index].values(
|
69
|
+
self[index].values(redis)
|
66
70
|
end
|
67
71
|
|
68
72
|
def index_ops(object, pk)
|
69
73
|
current_values_name = current_values_name(pk)
|
70
|
-
|
71
|
-
current_values =
|
74
|
+
redis.watch current_values_name
|
75
|
+
current_values = redis.hgetall(current_values_name)
|
72
76
|
|
73
77
|
ops = full_index_list.collect do |name,index|
|
74
78
|
value = index.read_normalized(object)
|
75
79
|
old_value = current_values[name]
|
76
80
|
|
77
|
-
((watch = index.watch(value, old_value)) &&
|
81
|
+
((watch = index.watch(value, old_value)) && redis.watch(*watch))
|
78
82
|
|
79
83
|
next if value == old_value
|
80
84
|
current_values[name] = value unless index.attribute_immutable?
|
81
85
|
|
82
|
-
next unless index.filter(
|
86
|
+
next unless index.filter(redis, object, value)
|
83
87
|
|
84
|
-
query_value = index.query(
|
88
|
+
query_value = index.query(redis, value)
|
85
89
|
proc do
|
86
|
-
index.index(
|
90
|
+
index.index(redis, pk, object, value, old_value, *query_value)
|
87
91
|
end
|
88
92
|
end.compact
|
89
93
|
|
90
94
|
ops << proc do
|
91
|
-
|
95
|
+
redis.hmset(current_values_name, *current_values.flatten)
|
92
96
|
end if current_values.any?
|
93
97
|
|
94
98
|
ops
|
@@ -107,8 +111,8 @@ module Relix
|
|
107
111
|
|
108
112
|
handle_concurrent_modifications(pk) do
|
109
113
|
current_values_name = current_values_name(pk)
|
110
|
-
|
111
|
-
current_values =
|
114
|
+
redis.watch current_values_name
|
115
|
+
current_values = redis.hgetall(current_values_name)
|
112
116
|
|
113
117
|
full_index_list.map do |name, index|
|
114
118
|
old_value = if index.attribute_immutable?
|
@@ -117,24 +121,24 @@ module Relix
|
|
117
121
|
current_values[name]
|
118
122
|
end
|
119
123
|
|
120
|
-
((watch = index.watch(old_value)) && !watch.empty? &&
|
121
|
-
proc { index.deindex(
|
122
|
-
end.tap { |ops| ops << proc {
|
124
|
+
((watch = index.watch(old_value)) && !watch.empty? && redis.watch(*watch))
|
125
|
+
proc { index.deindex(redis, pk, old_value) }
|
126
|
+
end.tap { |ops| ops << proc { redis.del current_values_name } }
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
130
|
def deindex_by_primary_key!(pk)
|
127
131
|
handle_concurrent_modifications(pk) do
|
128
132
|
current_values_name = current_values_name(pk)
|
129
|
-
|
130
|
-
current_values =
|
133
|
+
redis.watch current_values_name
|
134
|
+
current_values = redis.hgetall(current_values_name)
|
131
135
|
|
132
136
|
full_index_list.map do |name, index|
|
133
137
|
old_value = current_values[name]
|
134
138
|
|
135
|
-
((watch = index.watch(old_value)) && !watch.empty? &&
|
136
|
-
proc { index.deindex(
|
137
|
-
end.tap { |ops| ops << proc {
|
139
|
+
((watch = index.watch(old_value)) && !watch.empty? && redis.watch(*watch))
|
140
|
+
proc { index.deindex(redis, pk, old_value) }
|
141
|
+
end.tap { |ops| ops << proc { redis.del current_values_name } }
|
138
142
|
end
|
139
143
|
end
|
140
144
|
|
@@ -171,7 +175,7 @@ module Relix
|
|
171
175
|
loop do
|
172
176
|
ops = yield
|
173
177
|
|
174
|
-
results =
|
178
|
+
results = redis.multi do
|
175
179
|
ops.each do |op|
|
176
180
|
op.call(primary_key)
|
177
181
|
end
|
data/lib/relix/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel Talbott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
prerelease: false
|