alchemy-json_api 0.24.0 → 0.25.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: 6c6090af6d711e4a909628207f0b5f7d916944c60a8482b5b7ff958a38633d73
4
- data.tar.gz: 4e70e1de9b2ab1a68ce359c32973deac67a0965ade5021a7cf398ea29bf83a82
3
+ metadata.gz: b099850c244a74a544ab7d649f40faee72d021abee257d55ae9061e55c594dfd
4
+ data.tar.gz: '029e828a551ab68cdc8d1e48d26135ddc43bda3c3aca7565012ed55e40b1f1f8'
5
5
  SHA512:
6
- metadata.gz: 56d2a3623ad9e3a8585d5487f94f08c3d4a31f17a177f300252056eec68f5f4223eb86f32eca26238c5d52ecc6481a39d845b8082ea3d5cb4daec2fc25004a92
7
- data.tar.gz: 30ca7d8ca1e07d9e924e395ee42c0d4cbf693180052a70f003ccd592267564c2e701aea50462f24f659aad8f39c687d42fa90f05da2633ce2c90a82228a9a3c0
6
+ metadata.gz: d9f1c8b7b5e8996ea8edc83d30aecb780d5ff782530f09e8aaf43fc2a38b01e34867e79fc52bac2ecb4be6e5cc5b6ce6cbd2b478fa1d294574d56ebebfe4cd2c
7
+ data.tar.gz: 4f7efea149006aad79e341939bfa946fa5e87939315eefdfff8ef22f3e4d83b4f9b9a480b4ba058497b1a8f85c3729a2453fd956dff9570debbe384ccfb846cb
@@ -10,15 +10,10 @@ module Alchemy
10
10
 
11
11
  jsonapi_filter(page_scope, allowed) do |filtered_pages|
12
12
  @pages = filtered_pages.result
13
- if stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key)&.cache_key)
14
- # Only load pages with all includes when browser cache is stale
15
- jsonapi_filter(page_scope_with_includes, allowed) do |filtered|
16
- # decorate with our page model that has a eager loaded elements collection
17
- filtered_pages = filtered.result.map { |page| api_page(page) }
18
- jsonapi_paginate(filtered_pages) do |paginated|
19
- render jsonapi: paginated
20
- end
21
- end
13
+ if !@pages.all?(&:cache_page?)
14
+ render_pages_json(allowed) && return
15
+ elsif stale?(last_modified: @pages.maximum(:published_at), etag: @pages.max_by(&:cache_key)&.cache_key)
16
+ render_pages_json(allowed)
22
17
  end
23
18
  end
24
19
 
@@ -26,6 +21,10 @@ module Alchemy
26
21
  end
27
22
 
28
23
  def show
24
+ if !@page.cache_page?
25
+ render(jsonapi: api_page(load_page)) && return
26
+ end
27
+
29
28
  if stale?(last_modified: last_modified_for(@page), etag: @page.cache_key)
30
29
  # Only load page with all includes when browser cache is stale
31
30
  render jsonapi: api_page(load_page)
@@ -36,6 +35,17 @@ module Alchemy
36
35
 
37
36
  private
38
37
 
38
+ def render_pages_json(allowed)
39
+ # Only load pages with all includes when browser cache is stale
40
+ jsonapi_filter(page_scope_with_includes, allowed) do |filtered|
41
+ # decorate with our page model that has a eager loaded elements collection
42
+ filtered_pages = filtered.result.map { |page| api_page(page) }
43
+ jsonapi_paginate(filtered_pages) do |paginated|
44
+ render jsonapi: paginated
45
+ end
46
+ end
47
+ end
48
+
39
49
  def cache_duration
40
50
  ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", 3).to_i.hours
41
51
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Alchemy
3
3
  module JsonApi
4
- VERSION = "0.24.0"
4
+ VERSION = "0.25.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-05 00:00:00.000000000 Z
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.2.26
193
+ rubygems_version: 3.1.6
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: A JSONAPI compliant API for AlchemyCMS