extendi-cassandra_object 1.0.18 → 1.0.19

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
  SHA256:
3
- metadata.gz: 35c334a18f8c02dcc3fa80aedd61b32d750ad798199d4ead39c4fc5948cf6bc8
4
- data.tar.gz: 5d31df130a07772d2334d0c8dc97d14cfd6dd6e7d2bf3f5369d5d84206698a34
3
+ metadata.gz: db5689a9457f279a1fbe638e83d899b6ca640563b7d1332e8d741fc6afb5834e
4
+ data.tar.gz: f9d9ad2c05797b892f79c5e57953e20be272b85905365d86a4d62ae793d3e6f4
5
5
  SHA512:
6
- metadata.gz: 4dce7aed3855ebacfef2b79df27b0b598ca3f7caaa144e468560acbf1b823435ed3564ecd12922909fda502f5f2db69562823fd4e304a533a13af5cf9352d339
7
- data.tar.gz: f78455454cb989f92c9190a6c421570e3cbd402b7aa3613aa18d4a334c038ef65b3dafa054b477c0c5d7e5ddf9c587893cf1a69db4489f2aa6e8050b528efd30
6
+ metadata.gz: f64fad5dbbce31d041661b7033dfd967f576e54f0a9a2375784183622bb24c9ee671c43fc5839e91bd289954441060ec2a96304663354f07abf6f499fa8d97ac
7
+ data.tar.gz: a410cfabfafa3dee262fa0fa20f4e5670f7306f6691ca4bcb4b21cb8e04c5bb488ab3ff8aa8c61fb5ab33bc805f5a377c3bc823169099f49a697f1b325b5aa2f
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'extendi-cassandra_object'
5
- s.version = '1.0.18'
5
+ s.version = '1.0.19'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ['Duccio Giovannelli', 'gotime']
@@ -50,15 +50,25 @@ module CassandraObject
50
50
  end
51
51
  end
52
52
 
53
- def find_some(ids)
54
- ids = ids.flatten
53
+ def find_some(pids)
54
+ ids = pids.flatten.compact.uniq.map(&:to_s)
55
55
  return [] if ids.empty?
56
- ids = ids.compact.map(&:to_s).uniq
57
- where_ids(ids).execute
56
+
57
+ qr = where_ids(ids).execute
58
+ is_dymnamic = qr.is_a?(Hash)
59
+
60
+ results = qr.sort_by do |r|
61
+ id = r.keys.first if r.is_a?(Hash)
62
+ id = r[0] if r.is_a?(Array)
63
+ id = r.id if id.nil?
64
+ ids.index(id)
65
+ end
66
+
67
+ is_dymnamic ? Hash[results] : results
58
68
  end
59
69
 
60
70
  def not_found(id)
61
- raise CassandraObject::RecordNotFound, "Couldn't find #{self.name} with key #{id.inspect}"
71
+ raise CassandraObject::RecordNotFound, "Couldn't find #{name} with key #{id.inspect}"
62
72
  end
63
73
  end
64
74
  end
@@ -4,7 +4,6 @@
4
4
  require 'test_helper'
5
5
 
6
6
  class CassandraObject::PersistenceSchemaCkTest < CassandraObject::TestCase
7
-
8
7
  test 'composite key' do
9
8
  time1 = Time.now
10
9
  time2 = time1 + 1.second
@@ -25,19 +24,17 @@ class CassandraObject::PersistenceSchemaCkTest < CassandraObject::TestCase
25
24
  item = res[1]
26
25
  assert_equal '1', item.id
27
26
  assert_equal time2.to_i, item.date.to_i
28
-
29
27
  end
30
28
 
31
29
  test 'delete' do
32
30
  IssueSchemaCk.create(id: '1', type: 'first', date: Time.now, value: 1.to_f)
33
31
  IssueSchemaCk.create(id: '1', type: 'second', date: Time.now, value: 1.to_f)
34
-
35
32
  IssueSchemaCk.delete('1')
36
33
  assert_equal 0, IssueSchemaCk.find_by_id([1]).size
37
34
  end
38
35
 
39
36
  test 'delete with attributes' do
40
- time = Time.now
37
+ time = Time.now - 10.days
41
38
  IssueSchemaCk.create(id: '1', type: 'first', date: time, value: 1.to_f)
42
39
  IssueSchemaCk.create(id: '1', type: 'first', date: Time.now, value: 1.to_f)
43
40
  IssueSchemaCk.create(id: '2', type: 'first', date: time, value: 1.to_f)
@@ -65,5 +62,4 @@ class CassandraObject::PersistenceSchemaCkTest < CassandraObject::TestCase
65
62
  IssueSchemaCk.find_by_id(['1']).first.destroy
66
63
  assert_equal 1, IssueSchemaCk.find_by_id([1]).size
67
64
  end
68
-
69
65
  end
@@ -26,6 +26,39 @@ class CassandraObject::FinderMethodsTest < CassandraObject::TestCase
26
26
  assert_equal [first_issue, second_issue].to_set, Issue.find([first_issue.id, second_issue.id]).to_set
27
27
  end
28
28
 
29
+ test 'IssueDynamic: find with ids sorted' do
30
+ ids = (0..999).to_a.map(&:to_s)
31
+ ids.each do |i|
32
+ IssueDynamic.create(key: i, title: "foo_title_#{i}")
33
+ end
34
+ ids_to_find = ids.sample(10)
35
+ assert_equal ids_to_find, IssueDynamic.find(ids_to_find).keys
36
+ IssueDynamic.delete_all
37
+ end
38
+
39
+ test 'Issue: find with ids sorted' do
40
+ ids = (0..999).to_a.map(&:to_s)
41
+ ids.each do |i|
42
+ Issue.create(id: i, title: "foo_title_#{i}")
43
+ end
44
+ ids_to_find = ids.sample(10)
45
+ assert_equal ids_to_find, Issue.find(ids_to_find).map(&:id)
46
+ Issue.delete_all
47
+ end
48
+
49
+ test 'IssueSchemaCk: find with ids sorted' do
50
+ ids = (0..999).to_a.map(&:to_s)
51
+ time = Time.now - 10.years
52
+ ids.each do |i|
53
+ IssueSchemaCk.create(id: i, type: 'first', date: time, value: 1.to_f)
54
+ IssueSchemaCk.create(id: i, type: 'first', date: Time.now, value: 1.to_f)
55
+ end
56
+ ids_to_find = ids.sample(10)
57
+ assert_equal ids_to_find.size * 2, IssueSchemaCk.find(ids_to_find).map(&:id).size
58
+ assert_equal ids_to_find, IssueSchemaCk.find(ids_to_find).map(&:id).uniq
59
+ IssueSchemaCk.delete_all
60
+ end
61
+
29
62
  test 'find_by_id' do
30
63
  Issue.create.tap do |issue|
31
64
  assert_equal issue, Issue.find_by_id(issue.id)
@@ -64,9 +97,7 @@ class CassandraObject::FinderMethodsTest < CassandraObject::TestCase
64
97
  IssueDynamic.delete(['1', '2'])
65
98
  end
66
99
 
67
-
68
100
  test 'find all in batches dynamic paged' do
69
-
70
101
  issues = []
71
102
  100.times.each do |i|
72
103
  issues << IssueDynamic.create(key: i, title: 'tit', dynamic_field1: 'one', dynamic_field2: 'two')
@@ -135,5 +166,4 @@ class CassandraObject::FinderMethodsTest < CassandraObject::TestCase
135
166
  # first_issue = IssueDynamic.create(key: '1', title: 'tit', dynamic_field1: 'one', dynamic_field2: 'two')
136
167
  # f = IssueDynamic.first
137
168
  # end
138
-
139
169
  end
@@ -37,5 +37,4 @@ class CassandraObject::Scope::QueryMethodsTest < CassandraObject::TestCase
37
37
  foo_issue_columns = Issue.columns.first
38
38
  assert_equal ['created_at', 'description', 'title', 'updated_at'], foo_issue_columns[foo_issue_columns.keys.first]
39
39
  end
40
-
41
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extendi-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.18
4
+ version: 1.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duccio Giovannelli
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-18 00:00:00.000000000 Z
12
+ date: 2019-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel