alchemy-json_api 2.1.0 → 2.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 998909ab79b771f8adf243e5aa3878116ff30b0292990676f2e3e66c9bcf7df4
|
4
|
+
data.tar.gz: 5981655e53fbd3af1d1d70260122db353b3f0cbf81622bb7ac2f891f6fcc3fdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 372fe15209e5eb39a767d40914cbe2bf77b4a7014e7db764bccf762206e019772d7fa9833fec19df80245b078acf2ee483e064829e37b824da613ff0dba68e6a
|
7
|
+
data.tar.gz: 3ee1be6b2024a95645d15aa4d98e6882fd356a31ca96263128a5ef9ac75aedd88679852816368f7988932550d906ac7fcdc5c821b51878c12f10cf096a222270
|
@@ -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.2.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-05-
|
12
|
+
date: 2024-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: alchemy_cms
|