gotime-cassandra_object 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gotime-cassandra_object (2.1.0)
4
+ gotime-cassandra_object (2.1.1)
5
5
  cassandra (~> 0.11.3)
6
6
  rails (~> 3.0)
7
7
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '2.1.1'
5
+ s.version = '2.1.2'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -8,6 +8,24 @@ module CassandraObject
8
8
  yield instantiate(k, v)
9
9
  end
10
10
  end
11
+
12
+ def find_in_batches(options = {})
13
+ batch_size = options.delete(:batch_size) || 1000
14
+
15
+ batch = []
16
+
17
+ find_each do |record|
18
+ batch << record
19
+ if batch.size == batch_size
20
+ yield(batch)
21
+ batch = []
22
+ end
23
+ end
24
+
25
+ if batch.size > 0
26
+ yield batch
27
+ end
28
+ end
11
29
  end
12
30
  end
13
31
  end
@@ -2,11 +2,11 @@ module CassandraObject
2
2
  module FinderMethods
3
3
  extend ActiveSupport::Concern
4
4
  module ClassMethods
5
- def all(keyrange = ''..'', options = {})
5
+ def all(options = {})
6
6
  options = {:consistency => self.read_consistency, :limit => 100}.merge(options)
7
7
  count = options[:limit]
8
- results = ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, start_key: keyrange.first, finish_key: keyrange.last, key_count: count) do
9
- connection.get_range(column_family, start: keyrange.first, finish: keyrange.last, key_count: count, consistency: consistency_for_thrift(options[:consistency]))
8
+ results = ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: count) do
9
+ connection.get_range(column_family, key_count: count, consistency: consistency_for_thrift(options[:consistency]))
10
10
  end
11
11
 
12
12
  results.map do |k, v|
@@ -14,12 +14,8 @@ module CassandraObject
14
14
  end.compact
15
15
  end
16
16
 
17
- # def find()
18
-
19
- # end
20
-
21
- def first(keyrange = ''..'', options = {})
22
- all(keyrange, options.merge(:limit => 1)).first
17
+ def first(options = {})
18
+ all(options.merge(:limit => 1)).first
23
19
  end
24
20
 
25
21
  def find_with_ids(*ids)
data/test/batches_test.rb CHANGED
@@ -12,4 +12,19 @@ class CassandraObject::BatchesTest < CassandraObject::TestCase
12
12
 
13
13
  assert_equal Issue.all.to_set, issues.to_set
14
14
  end
15
+
16
+ test 'find_in_batches' do
17
+ Issue.create
18
+ Issue.create
19
+ Issue.create
20
+
21
+ issue_batches = []
22
+ Issue.find_in_batches(batch_size: 2) do |issues|
23
+ issue_batches << issues
24
+ end
25
+
26
+ assert_equal 2, issue_batches.size
27
+ assert issue_batches.any? { |issues| issues.size == 2 }
28
+ assert issue_batches.any? { |issues| issues.size == 1 }
29
+ end
15
30
  end
data/test/test_helper.rb CHANGED
@@ -14,7 +14,8 @@ module CassandraObject
14
14
  setup do
15
15
  CassandraObject::Base.establish_connection(
16
16
  keyspace: 'place_directory_development',
17
- servers: '192.168.0.100:9160'
17
+ # servers: '192.168.0.100:9160'
18
+ servers: '127.0.0.1:9160'
18
19
  )
19
20
  end
20
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotime-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-25 00:00:00.000000000Z
13
+ date: 2011-07-26 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &2152615720 !ruby/object:Gem::Requirement
17
+ requirement: &2153248160 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152615720
25
+ version_requirements: *2153248160
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cassandra
28
- requirement: &2152615260 !ruby/object:Gem::Requirement
28
+ requirement: &2153247700 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.11.3
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2152615260
36
+ version_requirements: *2153247700
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &2152614800 !ruby/object:Gem::Requirement
39
+ requirement: &2153247240 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2152614800
47
+ version_requirements: *2153247240
48
48
  description: Cassandra ActiveModel
49
49
  email: gems@gotime.com
50
50
  executables: []