grape-listing 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45e458a8f8256d37914e7844b87ab5ca89a828649e7de41743495dafa2122bbd
4
- data.tar.gz: 6fc8dd5d2f6ae95c8122c74f895129282835bf42c45d8fd8f553d6df69102f16
3
+ metadata.gz: 44f1d43a25f9fdf1f78ebca77acca29913d00b5c3f1ee74f909e121569a6255d
4
+ data.tar.gz: 466b6e2e8d755285a9b2208a4998555b14bd6d9a69f9a9b06a2ac1ba97dfef94
5
5
  SHA512:
6
- metadata.gz: 87a26725a413209783864fb440ea285aaae589b80597f4ae23217dd135e1c380fd3ba8d6e3e74640bb2890d4a947ac1c41a6c75ba2560c862c3f56cf4ff0f44d
7
- data.tar.gz: 470b431dbb7f26af609bfe09de5ad38ddb3cf7d004880c276ed8c77acade62107a88f57dc6a936b0a385fa349f5908be55a58b8e6c62f241f61e612dde1e1641
6
+ metadata.gz: 9d562cd66687f45f68096a83d9f84d8be5b3cd2e69a15409acb7f8179077a83eaef81dd636d245428be8e07602bcbd1b7774b5f03eb3756a96cbc4eb900d229b
7
+ data.tar.gz: c9ab0900cac1168df94db626a6fd09d845babef14ff0e9d49efa091b52f6b2ed206e538fa7d8983674ffc5ae636a397ef057c95165c873ac79784783f6b5aa4c
data/lib/grape/dsl.rb CHANGED
@@ -3,7 +3,12 @@ module Grape
3
3
  module InsideRoute
4
4
 
5
5
  def listing(model:, entity:, scopes: nil, search: nil, paginate: true, caching: false)
6
- opts = listing_opts(model, entity, scopes, search, caching)
6
+ # параметры запроса API
7
+ request_method = request.env['REQUEST_METHOD']
8
+ request_uri = request.env['REQUEST_URI']
9
+
10
+ # опции для сервиса
11
+ opts = listing_opts(model, entity, scopes, search, caching, request_method, request_uri)
7
12
 
8
13
  if params[:spreadsheet]
9
14
  listing_spreadsheet(**opts)
@@ -16,9 +21,9 @@ module Grape
16
21
 
17
22
  private
18
23
 
19
- def listing_opts(model, entity, scopes, search, caching)
24
+ def listing_opts(model, entity, scopes, search, caching, request_method, request_uri)
20
25
  # стандартные опции
21
- opts = { model:, entity:, scopes:, search:, params:, current_user:, caching: }
26
+ opts = { model:, entity:, scopes:, search:, params:, current_user:, caching:, request_method:, request_uri: }
22
27
 
23
28
  # требуемый список полей (+стандартные) для фильтрации в Grape Entity
24
29
  if params[:columns]
data/lib/grape_listing.rb CHANGED
@@ -5,7 +5,7 @@ require 'grape_listing_service'
5
5
  module GrapeListing
6
6
 
7
7
  def self.cache
8
- @cache ||= ActiveSupport::Cache.lookup_store(:mem_cache_store)
8
+ @cache ||= ActionController::Base.cache_store
9
9
  end
10
10
 
11
11
  end
@@ -7,6 +7,10 @@ module GrapeListing
7
7
  # обрабатываемая модель
8
8
  @model = args[:model]
9
9
 
10
+ # параметры адреса запроса API
11
+ @request_method = args[:request_method]
12
+ @request_uri = args[:request_uri]
13
+
10
14
  # параметры запроса и текущий пользователь
11
15
  @params = args[:params].stringify_keys
12
16
  @current_user = args[:current_user]
@@ -49,8 +53,8 @@ module GrapeListing
49
53
 
50
54
  def records_count
51
55
  # получение кол-ва записей из кеша
52
- cache_key = "#{@model}_records_count"
53
- cached = GrapeListing.cache.read(cache_key)
56
+ key = count_cache_key
57
+ cached = GrapeListing.cache.read(key)
54
58
  return cached if cached
55
59
 
56
60
  # получение кол-ва записей из запроса к БД
@@ -58,11 +62,19 @@ module GrapeListing
58
62
 
59
63
  # кеширование кол-ва записей при превышении порогового значения
60
64
  if count >= 1_000
61
- GrapeListing.cache.write(cache_key, count, expires_in: 30.minutes)
65
+ GrapeListing.cache.write(key, count, expires_in: 30.minutes)
62
66
  end
63
67
 
64
68
  count
65
69
  end
66
70
 
71
+ def count_cache_key
72
+ # пример: "GET api/v1/users?active=true"
73
+ body = "#{@request_method} #{@request_uri}"
74
+
75
+ enc = Digest::MD5.hexdigest(body)
76
+ "listing_cached_count_#{enc}"
77
+ end
78
+
67
79
  end
68
80
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-listing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Павел Бабин
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-15 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.8'
41
- - !ruby/object:Gem::Dependency
42
- name: dalli
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.2'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.2'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: fast_excel
57
43
  requirement: !ruby/object:Gem::Requirement