second_level_cache 2.3.1 → 2.3.2

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: 4ca8ef3f66bcc6dcc76e93958357d577a63a4769
4
- data.tar.gz: f90a4c724367d36589712a31df03723c2f4b7248
3
+ metadata.gz: 9fd6197c452055e9009c07da895d21ea853b132b
4
+ data.tar.gz: a0d81043575caa9d6093c9dd51fe1e84d2bff1f7
5
5
  SHA512:
6
- metadata.gz: 2a544566618c8643153d1bbd7c764878323b67e731cded7b1a0419866f8be54564a4fc8bcfb4c6a6511aa6ee54ad3e7824fc0887206463aed2146d075bb18fd8
7
- data.tar.gz: c94834042b2d630e6a3281af8cfedac728d9e4e7f76df5bd6230b577eb2669451391881bb732c42416c15ee1eeee8aff162abe4f9186d401bc28913fef98747d
6
+ metadata.gz: a439c2b62f440b2d4d7cb9344a586273cca00d4858f5d1a417393639ff89afbc58875b305a08e69be31d7397b44406f8a033ee43b9d6572c071b7ff3a7fd161c
7
+ data.tar.gz: 3088fdd16e92a72769dab464d413cd4e788038818bf655b3a785addc6751d39a3cc0210b0799eb58f484bcf28e8f0421f7c04e9e9361e124ea7d60750eed791e
@@ -11,10 +11,10 @@ module SecondLevelCache
11
11
  # NOTICE
12
12
  # Rails.cache.read_multi return hash that has keys only hitted.
13
13
  # eg. Rails.cache.read_multi(1,2,3) => {2 => hit_value, 3 => hit_value}
14
- hitted_ids = records_from_cache.map { |key, _| key.split('/')[2].to_i }
15
- missed_ids = ids.map(&:to_i) - hitted_ids
14
+ hitted_ids = records_from_cache.map { |key, _| key.split('/')[2] }
15
+ missed_ids = ids.map(&:to_s) - hitted_ids
16
16
 
17
- ::SecondLevelCache.logger.info "missed ids -> #{missed_ids.inspect} | hitted ids -> #{hitted_ids.inspect}"
17
+ ::SecondLevelCache.logger.info "missed ids -> #{missed_ids.join(',')} | hitted ids -> #{hitted_ids.join(',')}"
18
18
 
19
19
  record_marshals = RecordMarshal.load_multi(records_from_cache.values)
20
20
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SecondLevelCache
3
- VERSION = '2.3.1'.freeze
4
+ VERSION = '2.3.2'.freeze
4
5
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  Write-Through: As objects are created, updated, and deleted, all of the caches are automatically kept up-to-date and coherent.
16
16
  SUMMARY
17
17
 
18
- gem.homepage = 'https://github.com/csdn-dev/second_level_cache'
18
+ gem.homepage = 'https://github.com/hooopo/second_level_cache'
19
19
 
20
20
  gem.files = Dir.glob('lib/**/*.rb') + [
21
21
  'README.md',
@@ -0,0 +1,12 @@
1
+ ActiveRecord::Base.connection.create_table(:orders, force: true, id: :uuid) do |t|
2
+ t.text :body
3
+ t.string :title
4
+
5
+ t.timestamps null: false
6
+ end
7
+
8
+ class Order < ActiveRecord::Base
9
+ second_level_cache
10
+
11
+ has_many :order_items
12
+ end
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Base.connection.create_table(:order_items, force: true, id: :uuid) do |t|
2
+ t.text :body
3
+ t.string :slug
4
+ t.string :order_id
5
+ end
6
+
7
+ class OrderItem < ActiveRecord::Base
8
+ second_level_cache
9
+ belongs_to :order, touch: true
10
+ end
data/test/model/user.rb CHANGED
@@ -29,7 +29,7 @@ class User < ActiveRecord::Base
29
29
 
30
30
  serialize :options, Array
31
31
  serialize :json_options, JSON if ::ActiveRecord::VERSION::STRING >= '4.1.0'
32
- store :extras, accessors: [:tagline, :gender]
32
+ store :extras, accessors: %i[tagline gender]
33
33
 
34
34
  has_one :account
35
35
  has_one :forked_user_link, foreign_key: 'forked_to_user_id'
@@ -39,7 +39,7 @@ class User < ActiveRecord::Base
39
39
  has_many :books
40
40
  has_many :images, as: :imagable
41
41
 
42
- enum status: [:active, :archived]
42
+ enum status: %i[active archived]
43
43
  end
44
44
 
45
45
  class Namespace < ActiveRecord::Base
@@ -20,7 +20,7 @@ class PersistenceTest < ActiveSupport::TestCase
20
20
  def test_should_update_cache_after_touch
21
21
  old_updated_time = @user.updated_at
22
22
  @user.touch
23
- assert !(old_updated_time == @user.updated_at)
23
+ assert old_updated_time != @user.updated_at
24
24
  new_user = User.find @user.id
25
25
  assert_equal new_user, @user
26
26
  end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class PreloaderNonIntegerTest < ActiveSupport::TestCase
4
+ def test_belongs_to_preload_caches_includes_uuid
5
+ orders = [
6
+ Order.create(id: '15944214-e4df-4e46-8d56-1f5864a0b90c', title: 'title1', body: 'body1'),
7
+ Order.create(id: '25944214-e4df-4e46-8d56-1f5864a0b90c', title: 'title2', body: 'body2'),
8
+ Order.create(id: '35944214-e4df-4e46-8d56-1f5864a0b90c', title: 'title3', body: 'body3')
9
+ ]
10
+ orders.each_with_index { |order, i| order.order_items.create(body: "order_item#{order.id}", id: "1#{i}944214-e4df-4e46-8d56-1f5864a0b90c") }
11
+
12
+ results = nil
13
+ assert_queries(1) do
14
+ results = OrderItem.includes(:order).order('id ASC').to_a
15
+ end
16
+ assert_equal orders, results.map(&:order)
17
+ end
18
+
19
+ def test_belongs_to_when_read_multi_missed_from_cache_ar_will_fetch_missed_records_from_db_uuid
20
+ orders = [
21
+ Order.create(id: '15944214-e4df-4e46-8d56-1f5864a0b90c', title: 'title1', body: 'body1'),
22
+ Order.create(id: '25944214-e4df-4e46-8d56-1f5864a0b90c', title: 'title2', body: 'body2'),
23
+ Order.create(id: '35944214-e4df-4e46-8d56-1f5864a0b90c', title: 'title3', body: 'body3')
24
+ ]
25
+ orders.each_with_index { |order, i| order.order_items.create(body: "order_item#{order.id}", id: "1#{i}944214-e4df-4e46-8d56-1f5864a0b90c") }
26
+ expired_order = orders.first
27
+ expired_order.expire_second_level_cache
28
+
29
+ results = nil
30
+ assert_queries(2) do
31
+ assert_sql(/WHERE\s\"orders\"\.\"id\"\s=\s'#{expired_order.id}'/m) do
32
+ results = OrderItem.includes(:order).order('id ASC').to_a
33
+ end
34
+ end
35
+
36
+ assert_equal orders, results.map(&:order)
37
+ end
38
+
39
+ def test_has_many_preloader_returns_correct_results
40
+ order = Order.create(id: '15944214-e4df-4e46-8d56-1f5864a0b90c')
41
+ OrderItem.create(id: '11944214-e4df-4e46-8d56-1f5864a0b90c')
42
+ order_item = order.order_items.create(id: '12944214-e4df-4e46-8d56-1f5864a0b90c')
43
+
44
+ assert_equal [order_item], Order.includes(:order_items).find('15944214-e4df-4e46-8d56-1f5864a0b90c').order_items
45
+ end
46
+
47
+ def test_has_one_preloader_returns_correct_results
48
+ user = User.create(id: 1)
49
+ Account.create(id: 1)
50
+ account = user.create_account
51
+
52
+ assert_equal account, User.includes(:account).find(1).account
53
+ end
54
+ end
data/test/test_helper.rb CHANGED
@@ -18,6 +18,8 @@ require 'model/book'
18
18
  require 'model/image'
19
19
  require 'model/topic'
20
20
  require 'model/post'
21
+ require 'model/order'
22
+ require 'model/order_item'
21
23
  require 'model/account'
22
24
  require 'model/animal'
23
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: second_level_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -159,18 +159,21 @@ files:
159
159
  - test/model/animal.rb
160
160
  - test/model/book.rb
161
161
  - test/model/image.rb
162
+ - test/model/order.rb
163
+ - test/model/order_item.rb
162
164
  - test/model/post.rb
163
165
  - test/model/topic.rb
164
166
  - test/model/user.rb
165
167
  - test/persistence_test.rb
166
168
  - test/polymorphic_association_test.rb
169
+ - test/preloader_non_integer_test.rb
167
170
  - test/preloader_test.rb
168
171
  - test/record_marshal_test.rb
169
172
  - test/require_test.rb
170
173
  - test/second_level_cache_test.rb
171
174
  - test/single_table_inheritance_test.rb
172
175
  - test/test_helper.rb
173
- homepage: https://github.com/csdn-dev/second_level_cache
176
+ homepage: https://github.com/hooopo/second_level_cache
174
177
  licenses: []
175
178
  metadata: {}
176
179
  post_install_message:
@@ -210,11 +213,14 @@ test_files:
210
213
  - test/model/animal.rb
211
214
  - test/model/book.rb
212
215
  - test/model/image.rb
216
+ - test/model/order.rb
217
+ - test/model/order_item.rb
213
218
  - test/model/post.rb
214
219
  - test/model/topic.rb
215
220
  - test/model/user.rb
216
221
  - test/persistence_test.rb
217
222
  - test/polymorphic_association_test.rb
223
+ - test/preloader_non_integer_test.rb
218
224
  - test/preloader_test.rb
219
225
  - test/record_marshal_test.rb
220
226
  - test/require_test.rb