seamusabshere-cache-money 0.2.7 → 0.2.8

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.
data/lib/cash/finders.rb CHANGED
@@ -15,23 +15,38 @@ module Cash
15
15
  end
16
16
  end
17
17
 
18
+ def _default_order
19
+ @default_order ||= { :order => default_scope.first[:find][:order] || 'id ASC' }
20
+ end
21
+
22
+ def _find_scope_with_default_order
23
+ find_scope = scope(:find) || {}
24
+ find_scope[:order] ? find_scope : find_scope.merge(_default_order)
25
+ end
26
+
27
+ def find_by_id_with_exclusive_scope(id)
28
+ with_exclusive_scope({ :find => _default_order }) do
29
+ find_from_ids_without_cache([id], {})
30
+ end
31
+ end
32
+
18
33
  def without_cache(&block)
19
34
  with_scope(:find => {:readonly => true}, &block)
20
35
  end
21
36
 
22
37
  # User.find(:first, ...), User.find_by_foo(...), User.find(:all, ...), User.find_all_by_foo(...)
23
38
  def find_every_with_cache(options)
24
- Query::Select.perform(self, options, scope(:find))
39
+ Query::Select.perform(self, options, _find_scope_with_default_order)
25
40
  end
26
41
 
27
42
  # User.find(1), User.find(1, 2, 3), User.find([1, 2, 3]), User.find([])
28
43
  def find_from_ids_with_cache(ids, options)
29
- Query::PrimaryKey.perform(self, ids, options, scope(:find))
44
+ Query::PrimaryKey.perform(self, ids, options, _find_scope_with_default_order)
30
45
  end
31
46
 
32
47
  # User.count(:all), User.count, User.sum(...)
33
48
  def calculate_with_cache(operation, column_name, options = {})
34
- Query::Calculation.perform(self, operation, column_name, options, scope(:find))
49
+ Query::Calculation.perform(self, operation, column_name, options, _find_scope_with_default_order)
35
50
  end
36
51
  end
37
52
  end
@@ -116,10 +116,11 @@ module Cash
116
116
  alias_method :index_for, :indexed_on?
117
117
 
118
118
  def format_results(cache_keys, objects)
119
- return objects if objects.blank?
119
+ return [] if objects.blank? # nobody is depending on this returning nil, right?
120
120
 
121
121
  objects = convert_to_array(cache_keys, objects)
122
122
  objects = apply_limits_and_offsets(objects, @options1)
123
+ return [] if objects.blank?
123
124
  deserialize_objects(objects)
124
125
  end
125
126
 
@@ -155,7 +156,7 @@ module Cash
155
156
 
156
157
  def find_from_keys(*missing_keys)
157
158
  missing_ids = Array(missing_keys).flatten.collect { |key| key.split('/')[2].to_i }
158
- find_from_ids_without_cache(missing_ids, {})
159
+ missing_ids.map { |id| @active_record.find_by_id_with_exclusive_scope(id) }
159
160
  end
160
161
  end
161
162
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seamusabshere-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen