grape-listing 1.1.4 → 1.1.5
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 +4 -4
- data/lib/grape/dsl.rb +8 -3
- data/lib/listing_service/args_handling.rb +15 -3
- 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: ebde4f181db7c89e1def2eeb1af0fe820da5f89b0921dc88080d0b793f3d01ac
|
4
|
+
data.tar.gz: 5f077bb264dcf16c617be8a22c78e0769a1270af387ee2f171b78be398a35baa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cc783b3c30a87083033d825a7d80624af8d513c55989b6cd572a9dea1786caa72bc1306f50bf1a5f6ca6f136e9008b4c08a6b93713d4e5da58b12e06684500d
|
7
|
+
data.tar.gz: dde882747da769a523f0c31b4862327d8b959f667a14e5b151b92dca8de9b609204467c2b9bfbfc79e19b75a2b27b49243184ac434bb7ee858a496371b6c6c78
|
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
|
-
|
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]
|
@@ -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
|
-
|
53
|
-
cached = GrapeListing.cache.read(
|
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(
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-listing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Павел Бабин
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|