large_object_store 1.6.1 → 1.8.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
  SHA256:
3
- metadata.gz: a72748e1b76afaf0bf1f32ffddba01354405a7fd0d41ee5bdf5a29180259c5d8
4
- data.tar.gz: e16591860fd1542d994d49ace89c3f759f00c641c1566d780e6d3fc93afcb258
3
+ metadata.gz: 6f11e8dd54268874539335ca07d5a8cc1dfa2910e14bb81f6b1a506233727a4f
4
+ data.tar.gz: b2b5f7bf4610df371b4ca424e8efa5cc0d0c632c28e83fb6c083a45ccbb83ec3
5
5
  SHA512:
6
- metadata.gz: 0c0878955ba7c92f6fdbdfa9c25c2f8c4b6ef441863940732c804076d423f53a8d1a40aae7f06544a15779b81a7225ec367b65caa3e16a4c49c07952a5363c24
7
- data.tar.gz: 3d7c5fdc351ae6c0170ce41cf58696d08d2c1493e35324252ccd49511d977f1880ea00acfddfef741e4977feb201ac052a1270a743c5037befb57ba44edbbcaf
6
+ metadata.gz: 0e73adada15c374cef708d10ceb0829dca94c3251461735ef57ac2d707e7dd8b6eb1d6da1158d93510715b4763c63b4e679046e2313bff10a915bca4e8704475
7
+ data.tar.gz: e3b09f3345f4d090cfa33a73909769aa649a46bd7c75409e58d9e722a5ff354630f3bab98b3e27c64a7002755d3ff5c6cf86598903f0f885f23110a4789f7922
@@ -1,3 +1,3 @@
1
1
  module LargeObjectStore
2
- VERSION = "1.6.1"
2
+ VERSION = "1.8.0"
3
3
  end
@@ -27,21 +27,18 @@ module LargeObjectStore
27
27
  class RailsWrapper
28
28
  attr_reader :store
29
29
 
30
- def initialize(store, serializer: Marshal)
30
+ def initialize(store, serializer: Marshal, max_slice_size: MAX_OBJECT_SIZE)
31
31
  @store = store
32
32
  @serializer = serializer
33
+ @max_slice_size = [max_slice_size, MAX_OBJECT_SIZE].min
34
+ @namespace = (store.respond_to?(:options) && store.options[:namespace]) || ""
33
35
  end
34
36
 
35
37
  def write(key, value, **options)
36
38
  options = options.dup
37
39
  value = serialize(value, options)
38
40
 
39
- # calculate slice size; note that key length is a factor because
40
- # the key is stored on the same slab page as the value
41
- namespace = (store.respond_to?(:options) && store.options[:namespace]) || ""
42
- namespace_length = namespace.empty? ? 0 : namespace.size + 1
43
- slice_size = MAX_OBJECT_SIZE - ITEM_HEADER_SIZE - UUID_SIZE - key.bytesize - namespace_length
44
-
41
+ slice_size = safe_slice_size(key)
45
42
  # store number of pages
46
43
  pages = (value.size / slice_size.to_f).ceil
47
44
 
@@ -74,7 +71,7 @@ module LargeObjectStore
74
71
  # read sliced data
75
72
  keys = (1..pages).map { |i| key(key, i) }
76
73
  # use values_at to enforce key order because read_multi doesn't guarantee a return order
77
- slices = @store.read_multi(*keys).values_at(*keys)
74
+ slices = @store.read_multi(*keys, raw: true).values_at(*keys)
78
75
  return nil if slices.compact.size != pages
79
76
 
80
77
  slices = slices.map do |slice|
@@ -110,6 +107,19 @@ module LargeObjectStore
110
107
 
111
108
  private
112
109
 
110
+ # calculate slice size; note that key length is a factor because
111
+ # the key is stored on the same slab page as the value
112
+ def safe_slice_size(key)
113
+ namespace_length = @namespace.empty? ? 0 : @namespace.size + 1
114
+ overhead = ITEM_HEADER_SIZE + UUID_SIZE + key.bytesize + namespace_length
115
+ slice_size = @max_slice_size - overhead
116
+ if slice_size <= 0
117
+ MAX_OBJECT_SIZE - overhead
118
+ else
119
+ slice_size
120
+ end
121
+ end
122
+
113
123
  # convert a object to a string
114
124
  # modifies options
115
125
  def serialize(value, options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: large_object_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ana Martinez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-25 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zstd-ruby
@@ -45,14 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '2.6'
48
+ version: '3.0'
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.5.3
55
+ rubygems_version: 3.5.9
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: Store large objects in memcache or others