graphql-fragment_cache 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/graphql/fragment_cache/cacher.rb +20 -1
- data/lib/graphql/fragment_cache/fragment.rb +6 -7
- data/lib/graphql/fragment_cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ad57aeb345c05f3025f6cc232ec06b16afc603d4330451682f526c6516db71
|
4
|
+
data.tar.gz: e486c3090b73fbe3f372cf1a7557c9df9753c3ddcddd720d97d02f3294625dbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4a05c0bdc3aae4783cf6d0417feb70e3b56fe31f1c80a16fcf8b6cb9bf6da21e882be7a3458defc8d28fe8797f204852193356fe951891b3861bae88cbaed47
|
7
|
+
data.tar.gz: cdd254f8c323d82c63a9c15bd4c767ca96feee841c4a1f7f5a9059eb0fc166ef52878a68e2170239dd8e0d3b152646d111800ad08beedadeb4080fc2f542a694
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.0.5 (2020-10-13)
|
6
|
+
|
7
|
+
- [PR#35](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/35) Prefer using `#write_multi` on cache store when possible ([@DmitryTsepelev][])
|
8
|
+
|
5
9
|
## 1.0.4 (2020-10-12)
|
6
10
|
|
7
11
|
- [PR#34](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/34) Avoid unneded default calculation in CacheKeyBuilder ([@DmitryTsepelev][])
|
data/README.md
CHANGED
@@ -252,7 +252,7 @@ Rails.application.configure do |config|
|
|
252
252
|
end
|
253
253
|
```
|
254
254
|
|
255
|
-
⚠️ Cache store must implement `#read(key)`, `#
|
255
|
+
⚠️ Cache store must implement `#read(key)`, `#exist?(key)` and `#write_multi(hash, **options)` or `#write(key, value, **options)` methods.
|
256
256
|
|
257
257
|
The gem provides only in-memory store out-of-the-box (`GraphQL::FragmentCache::MemoryStore`). It's used by default.
|
258
258
|
|
@@ -10,7 +10,26 @@ module GraphQL
|
|
10
10
|
def call(query)
|
11
11
|
return unless query.context.fragments?
|
12
12
|
|
13
|
-
|
13
|
+
if FragmentCache.cache_store.respond_to?(:write_multi)
|
14
|
+
batched_persist(query)
|
15
|
+
else
|
16
|
+
persist(query)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def batched_persist(query)
|
23
|
+
query.context.fragments.group_by(&:options).each do |options, group|
|
24
|
+
hash = group.map { |fragment| [fragment.cache_key, fragment.value] }.to_h
|
25
|
+
FragmentCache.cache_store.write_multi(hash, **options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def persist(query)
|
30
|
+
query.context.fragments.each do |fragment|
|
31
|
+
FragmentCache.cache_store.write(fragment.cache_key, fragment.value, **fragment.options)
|
32
|
+
end
|
14
33
|
end
|
15
34
|
end
|
16
35
|
end
|
@@ -22,17 +22,16 @@ module GraphQL
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def persist
|
26
|
-
value = final_value.dig(*path)
|
27
|
-
FragmentCache.cache_store.write(cache_key, value, **options)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
25
|
def cache_key
|
33
26
|
@cache_key ||= CacheKeyBuilder.call(path: path, query: context.query, **options)
|
34
27
|
end
|
35
28
|
|
29
|
+
def value
|
30
|
+
final_value.dig(*path)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
36
35
|
def interpreter_context
|
37
36
|
context.namespace(:interpreter)
|
38
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-fragment_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|