global_uid 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f17fa1ca013a3522b17564a1a5221f6808fe5a13
4
- data.tar.gz: 2768edccf2ce2c846149b346533ef1723e0f4cea
3
+ metadata.gz: 3680d975cbe2d05025cbc770b25a6418e09d04ee
4
+ data.tar.gz: 5002baf9f29f436701bf087d26916e0e74d1e946
5
5
  SHA512:
6
- metadata.gz: 2ad21dd9b622a6c67314474d14b8150293a9b8c54350090e91ed58abd17cbe847280c0b6992b28db3c496ba9373e2dcd90ac791e2eca69cc4672d42d986f93fa
7
- data.tar.gz: 9b5e0e4f6a14f99c120cf5d1cd8cdab218bb886e260123fb3537c1dd8c47987a1287e1319c840f990d271e719fc302fa5a7b2c6ad83b683a6ef03d16d55bda8b
6
+ metadata.gz: 7ddcb75af62154ae5b815653fabe3ee66d8f95810d5ef7fe315738db7e105ddc5145984fa04f8eae848795d1e78a0a5247b1e7f11d8345c84b0ebfb872d295e8
7
+ data.tar.gz: 80055cb8046cda7b95fab72e7105d913749bd4bc80d893a0c957607a8dc6be0d72d8ce1e95ceca5c1ac41eb588a01ede9a92f7e8215bef935f5fc7b0a728e452
@@ -10,11 +10,9 @@ module GlobalUid
10
10
  return if GlobalUid::Base.global_uid_options[:disabled]
11
11
  return if self.class.global_uid_disabled
12
12
 
13
- global_uid = self.class.get_reserved_global_uid
14
- if !global_uid
15
- realtime = Benchmark::realtime do
16
- global_uid = self.class.generate_uid
17
- end
13
+ global_uid = nil
14
+ realtime = Benchmark::realtime do
15
+ global_uid = self.class.generate_uid
18
16
  end
19
17
 
20
18
  if GlobalUid::Base.global_uid_options[:dry_run]
@@ -63,28 +61,6 @@ module GlobalUid
63
61
  end
64
62
  @global_uid_table_exists = true
65
63
  end
66
-
67
- def with_reserved_global_uids(n_to_reserve)
68
- old_should_reserve = @should_reserve_global_uids
69
- @should_reserve_global_uids = n_to_reserve
70
- yield
71
- ensure
72
- @should_reserve_global_uids = old_should_reserve
73
- end
74
-
75
- def get_reserved_global_uid
76
- @reserved_global_uids ||= []
77
- id = @reserved_global_uids.shift
78
- return id if id
79
-
80
- if @should_reserve_global_uids
81
- @reserved_global_uids += GlobalUid::Base.get_many_uids_for_class(self, @should_reserve_global_uids)
82
- @reserved_global_uids.shift
83
- else
84
- nil
85
- end
86
- end
87
-
88
64
  end
89
65
  end
90
66
  end
@@ -195,26 +195,6 @@ module GlobalUid
195
195
  raise NoServersAvailableException, "All global UID servers are gone!"
196
196
  end
197
197
 
198
- def self.get_many_uids_for_class(klass, n, options = {})
199
- with_connections do |connection|
200
- GlobalUidTimer.timeout(self.global_uid_options[:query_timeout], TimeoutException) do
201
- connection.transaction do
202
- start_id = connection.select_value("SELECT id from #{klass.global_uid_table} where stub='a' FOR UPDATE").to_i
203
- connection.execute("update #{klass.global_uid_table} set id = id + #{n} * @@auto_increment_increment where stub='a'")
204
- if self.global_uid_options[:storage_engine] =~ /InnoDB/i
205
- # This is needed to reset the auto_increment counter on an InnoDB table.
206
- connection.execute("ALTER TABLE #{klass.global_uid_table} AUTO_INCREMENT = 1")
207
- end
208
- end_res = connection.select_one("SELECT id, @@auto_increment_increment as inc from #{klass.global_uid_table} where stub='a'")
209
- increment_by = end_res['inc'].to_i
210
- end_id = end_res['id'].to_i
211
- return (start_id + increment_by).step(end_id, increment_by).to_a
212
- end
213
- end
214
- end
215
- raise NoServersAvailableException, "All global UID servers are gone!"
216
- end
217
-
218
198
  def self.global_uid_options=(options)
219
199
  @global_uid_options = GLOBAL_UID_DEFAULTS.merge(options.symbolize_keys)
220
200
  end
@@ -1,11 +1,7 @@
1
1
  module GlobalUid
2
2
  module MigrationExtension
3
- def self.included(base)
4
- base.alias_method_chain :create_table, :global_uid
5
- base.alias_method_chain :drop_table, :global_uid
6
- end
7
3
 
8
- def create_table_with_global_uid(name, options = {}, &blk)
4
+ def create_table(name, options = {}, &blk)
9
5
  uid_enabled = !(GlobalUid::Base.global_uid_options[:disabled] || options[:use_global_uid] == false)
10
6
 
11
7
  # rules for stripping out auto_increment -- enabled, not dry-run, and not a "PK-less" table
@@ -16,7 +12,7 @@ module GlobalUid
16
12
  options.merge!(:id => false)
17
13
  end
18
14
 
19
- create_table_without_global_uid(name, options) { |t|
15
+ super(name, options) { |t|
20
16
  if remove_auto_increment
21
17
  # need to honor specifically named tables
22
18
  id_column_name = (old_id_option || :id)
@@ -32,12 +28,12 @@ module GlobalUid
32
28
 
33
29
  end
34
30
 
35
- def drop_table_with_global_uid(name, options = {})
31
+ def drop_table(name, options = {})
36
32
  if !GlobalUid::Base.global_uid_options[:disabled] && options[:use_global_uid] == true
37
33
  id_table_name = options[:global_uid_table] || GlobalUid::Base.id_table_from_name(name)
38
34
  GlobalUid::Base.drop_uid_tables(id_table_name,options)
39
35
  end
40
- drop_table_without_global_uid(name)
36
+ super(name, options)
41
37
  end
42
38
  end
43
39
  end
data/lib/global_uid.rb CHANGED
@@ -4,8 +4,6 @@ require "global_uid/migration_extension"
4
4
  require "global_uid/schema_dumper_extension"
5
5
 
6
6
  module GlobalUid
7
- VERSION = "1.4.1"
8
-
9
7
  class NoServersAvailableException < Exception ; end
10
8
  class ConnectionTimeoutException < Exception ; end
11
9
  class TimeoutException < Exception ; end
@@ -14,7 +12,7 @@ module GlobalUid
14
12
  end
15
13
 
16
14
  ActiveRecord::Base.send(:include, GlobalUid::ActiveRecordExtension)
17
- ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, GlobalUid::MigrationExtension)
15
+ ActiveRecord::Migration.send(:prepend, GlobalUid::MigrationExtension)
18
16
  if ActiveRecord::VERSION::MAJOR == 4 && RUBY_VERSION >= '2'
19
17
  ActiveRecord::SchemaDumper.send(:prepend, GlobalUid::SchemaDumperExtension)
20
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global_uid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Osheroff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -87,7 +87,7 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: shoulda
90
+ name: minitest
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
@@ -101,7 +101,7 @@ dependencies:
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
- name: mocha
104
+ name: minitest-rg
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
@@ -115,7 +115,7 @@ dependencies:
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  - !ruby/object:Gem::Dependency
118
- name: test-unit
118
+ name: mocha
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="