large_object_store 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/large_object_store/version.rb +1 -1
- data/lib/large_object_store.rb +17 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e72d3b11da68461fa95e282ad1f8727c0c397f87602a01557754a438c111f88d
|
4
|
+
data.tar.gz: a79ab553fd00bb63b89c584dda277c4faba58ce82d4095a7a73a16407d4995ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2eab6d7bf39128dda4096fc96dc583128e08d0b08acbce8ea879611be48c03024aacc2f0cb55d27827988ee024c1d291495f8c85bdeb12ba55becd34a634407
|
7
|
+
data.tar.gz: b991e5e5337333eeb39daade26edad8957819f8de768f2632df09f77873d9f351f5913d7dac19d5595115d3624369c88a8ddc9fd90a6967028db522221cadd96
|
data/lib/large_object_store.rb
CHANGED
@@ -27,19 +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
|
-
|
40
|
-
# the key is stored on the same slab page as the value
|
41
|
-
slice_size = MAX_OBJECT_SIZE - ITEM_HEADER_SIZE - UUID_SIZE - key.bytesize
|
42
|
-
|
41
|
+
slice_size = safe_slice_size(key)
|
43
42
|
# store number of pages
|
44
43
|
pages = (value.size / slice_size.to_f).ceil
|
45
44
|
|
@@ -108,6 +107,19 @@ module LargeObjectStore
|
|
108
107
|
|
109
108
|
private
|
110
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
|
+
|
111
123
|
# convert a object to a string
|
112
124
|
# modifies options
|
113
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.
|
4
|
+
version: 1.7.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:
|
11
|
+
date: 2024-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zstd-ruby
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.5.3
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Store large objects in memcache or others
|