alchemy-json_api 2.1.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/alchemy/json_api/admin/pages_controller.rb +1 -1
- data/app/controllers/alchemy/json_api/nodes_controller.rb +3 -1
- data/app/controllers/alchemy/json_api/pages_controller.rb +18 -7
- data/app/serializers/alchemy/json_api/page_serializer.rb +2 -1
- data/lib/alchemy/json_api/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: 69488e287d0cb294483885e5b03deaebcf94a0905cd181613c84c6be90f4582f
|
4
|
+
data.tar.gz: 5fcffd69254524ab47f3f30b592633ce7ede6fc4312f02571297073655d3e2d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef53c0124e8afd5eb85820362c5512be74a63659b1992b3aa43d22f884d9a5851fb1ae05722472b13873d3369c9ec475fa86de4329ec5b1c2d757271cf94032d
|
7
|
+
data.tar.gz: 3b7932b0e11841eabd4eeead158cdb54ac1484bd655629956354945383719e5f294736a7d74889b61c32a22f3f3befe19e1b3845abb9750b5c192e29ce453f53
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module Alchemy
|
4
4
|
module JsonApi
|
5
5
|
class NodesController < JsonApi::BaseController
|
6
|
+
THREE_HOURS = 10800
|
7
|
+
|
6
8
|
def index
|
7
9
|
@nodes = node_scope.select(:id, :updated_at)
|
8
10
|
if stale?(last_modified: @nodes.maximum(:updated_at), etag: @nodes)
|
@@ -17,7 +19,7 @@ module Alchemy
|
|
17
19
|
private
|
18
20
|
|
19
21
|
def cache_duration
|
20
|
-
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION",
|
22
|
+
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", THREE_HOURS).to_i
|
21
23
|
end
|
22
24
|
|
23
25
|
def jsonapi_meta(nodes)
|
@@ -3,6 +3,9 @@
|
|
3
3
|
module Alchemy
|
4
4
|
module JsonApi
|
5
5
|
class PagesController < JsonApi::BaseController
|
6
|
+
THREE_HOURS = 10800
|
7
|
+
JSONAPI_STALEMAKERS = %i[include fields sort filter page]
|
8
|
+
|
6
9
|
before_action :load_page_for_cache_key, only: :show
|
7
10
|
|
8
11
|
def index
|
@@ -10,9 +13,10 @@ module Alchemy
|
|
10
13
|
|
11
14
|
jsonapi_filter(page_scope, allowed) do |filtered_pages|
|
12
15
|
@pages = filtered_pages.result
|
16
|
+
|
13
17
|
if !@pages.all?(&:cache_page?)
|
14
18
|
render_pages_json(allowed) && return
|
15
|
-
elsif stale?(
|
19
|
+
elsif stale?(etag: etag(@pages))
|
16
20
|
render_pages_json(allowed)
|
17
21
|
end
|
18
22
|
end
|
@@ -25,7 +29,7 @@ module Alchemy
|
|
25
29
|
render(jsonapi: api_page(load_page)) && return
|
26
30
|
end
|
27
31
|
|
28
|
-
if stale?(
|
32
|
+
if stale?(etag: etag(@page))
|
29
33
|
# Only load page with all includes when browser cache is stale
|
30
34
|
render jsonapi: api_page(load_page)
|
31
35
|
end
|
@@ -47,7 +51,7 @@ module Alchemy
|
|
47
51
|
end
|
48
52
|
|
49
53
|
def cache_duration
|
50
|
-
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION",
|
54
|
+
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", THREE_HOURS).to_i
|
51
55
|
end
|
52
56
|
|
53
57
|
def caching_options
|
@@ -60,10 +64,6 @@ module Alchemy
|
|
60
64
|
.or(page_scope.where(urlname: params[:path])).first!
|
61
65
|
end
|
62
66
|
|
63
|
-
def last_modified_for(page)
|
64
|
-
page.published_at
|
65
|
-
end
|
66
|
-
|
67
67
|
def jsonapi_meta(pages)
|
68
68
|
pagination = jsonapi_pagination_meta(pages)
|
69
69
|
|
@@ -117,6 +117,17 @@ module Alchemy
|
|
117
117
|
Alchemy::JsonApi::Page.new(page, page_version_type: page_version_type)
|
118
118
|
end
|
119
119
|
|
120
|
+
def etag(pages)
|
121
|
+
pages = Array.wrap(pages)
|
122
|
+
return unless pages.any?
|
123
|
+
relevant_params = params.to_unsafe_hash.slice(*JSONAPI_STALEMAKERS).flatten.compact
|
124
|
+
pages.map { |page| page_cache_key(page) }.concat(relevant_params)
|
125
|
+
end
|
126
|
+
|
127
|
+
def page_cache_key(page)
|
128
|
+
page.cache_key_with_version
|
129
|
+
end
|
130
|
+
|
120
131
|
def base_page_scope
|
121
132
|
# cancancan is not able to merge our complex AR scopes for logged in users
|
122
133
|
if can?(:edit_content, ::Alchemy::Page)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alchemy-json_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Meyerhoff
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: alchemy_cms
|