acts_as_shardable 0.6.0 → 0.7.0
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/acts_as_shardable.gemspec +1 -1
- data/lib/acts_as_shardable.rb +44 -13
- data/lib/acts_as_shardable/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11ce4ec7bf911d8b8eb80a615a3dc81a229f93b1
|
4
|
+
data.tar.gz: 1cd6cc539c4bb61e219e6d7e402b8accc75306ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dea62a56bb346fe1616ca09af42773fec5fdf871b74371dcedfe7ed974d7e29f94a20981fa97bfd5c0778fe18e58d62a547a59c9a21ef0be11e335dab7692cd0
|
7
|
+
data.tar.gz: 7b1798568e693b7dcf7d05e723df46b1b641a3892570418a531bf18b488b5c2eeebecb9044d6e9726be5b04109eb4eb680b0c0d0b9f788d07654be24c46aad34
|
data/acts_as_shardable.gemspec
CHANGED
data/lib/acts_as_shardable.rb
CHANGED
@@ -24,6 +24,7 @@ module ActsAsShardable
|
|
24
24
|
# Updates the associated record with values matching those of the instance attributes.
|
25
25
|
# Returns the number of affected rows.
|
26
26
|
define_method :_update_record do |attribute_names = self.attribute_names|
|
27
|
+
attribute_names = keys_for_partial_write if self.class.base_class.partial_writes
|
27
28
|
|
28
29
|
was, is = changes[self.class.base_class.shard_method]
|
29
30
|
|
@@ -66,19 +67,26 @@ module ActsAsShardable
|
|
66
67
|
raise
|
67
68
|
end
|
68
69
|
else
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
if self.respond_to?(:attributes_with_values_for_update, true)
|
71
|
+
attributes_values = attributes_with_values_for_update(attribute_names)
|
72
|
+
else
|
73
|
+
attribute_names = attributes_for_update(attribute_names)
|
74
|
+
attributes_values = {}
|
75
|
+
arel_table = shard.arel_table
|
73
76
|
|
74
|
-
|
75
|
-
|
77
|
+
attribute_names.each do |name|
|
78
|
+
attributes_values[arel_table[name]] = typecasted_attribute_value(name)
|
79
|
+
end
|
76
80
|
end
|
77
81
|
|
78
82
|
if attributes_values.empty?
|
79
83
|
0
|
80
84
|
else
|
81
|
-
|
85
|
+
if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR >= 1
|
86
|
+
shard.unscoped._update_record(attributes_values, self.class.base_class.primary_key => id_in_database)
|
87
|
+
else
|
88
|
+
shard.unscoped._update_record(attributes_values, id, id_was)
|
89
|
+
end
|
82
90
|
end
|
83
91
|
end
|
84
92
|
end
|
@@ -102,7 +110,16 @@ module ActsAsShardable
|
|
102
110
|
changes[column] = write_attribute(column, current_time)
|
103
111
|
end
|
104
112
|
|
105
|
-
|
113
|
+
if locking_enabled?
|
114
|
+
if self.respond_to?(:increment_lock)
|
115
|
+
changes[self.class.base_class.locking_column] = increment_lock
|
116
|
+
else
|
117
|
+
lock_col = self.class.base_class.locking_column
|
118
|
+
previous_lock_value = read_attribute(lock_col)
|
119
|
+
self[lock_col] = previous_lock_value + 1
|
120
|
+
changes[lock_col] = self[lock_col]
|
121
|
+
end
|
122
|
+
end
|
106
123
|
|
107
124
|
clear_attribute_changes(changes.keys)
|
108
125
|
primary_key = self.class.primary_key
|
@@ -115,13 +132,27 @@ module ActsAsShardable
|
|
115
132
|
# Creates a record with values matching those of the instance attributes
|
116
133
|
# and returns its id.
|
117
134
|
define_method :_create_record do |attribute_names = self.attribute_names|
|
118
|
-
|
135
|
+
_run_create_callbacks {
|
136
|
+
attribute_names = keys_for_partial_write if self.class.base_class.partial_writes
|
137
|
+
attribute_names |= [self.class.base_class.locking_column] if locking_enabled?
|
119
138
|
|
120
|
-
|
121
|
-
|
139
|
+
if self.respond_to?(:attributes_with_values_for_create, true)
|
140
|
+
attributes_values = attributes_with_values_for_create(attribute_names)
|
141
|
+
else
|
142
|
+
attributes_values = arel_attributes_with_values_for_create(attribute_names)
|
143
|
+
end
|
122
144
|
|
123
|
-
|
124
|
-
|
145
|
+
if shard.respond_to?(:_insert_record)
|
146
|
+
new_id = shard.unscoped._insert_record attributes_values
|
147
|
+
else
|
148
|
+
new_id = shard.unscoped.insert attributes_values
|
149
|
+
end
|
150
|
+
|
151
|
+
self.id ||= new_id if self.class.base_class.primary_key
|
152
|
+
|
153
|
+
@new_record = false
|
154
|
+
id
|
155
|
+
}
|
125
156
|
end
|
126
157
|
|
127
158
|
private :_create_record
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_shardable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scorix
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: activerecord
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '4.
|
75
|
+
version: '4.2'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '4.
|
82
|
+
version: '4.2'
|
83
83
|
description: Let subclasses of ActiveRecord::Base to be shardable.
|
84
84
|
email:
|
85
85
|
- scorix@gmail.com
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.6.11
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Let subclasses of ActiveRecord::Base to be shardable.
|