ibrain-core 0.5.10 → 0.5.13

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: 330ce67ab6f228e04d3b6ca92feeb6dd7c6d604861abe797c8e582f2b15d431d
4
- data.tar.gz: d77dc76e8f9665b905dcdc927200db46ce7cc535d730dc54a5841f0cc42fe54b
3
+ metadata.gz: 600b958b07961ac273d90d3983dcc092468e9863daabf7c79dfd1243318bb76f
4
+ data.tar.gz: 6ae2ccaba1c837721b9d0003379af3cd8a5bd5854b03d0abb6e6826b250b252f
5
5
  SHA512:
6
- metadata.gz: 69a63bc198060fd596b93fbd164827950261da9bcd8105426a3f5965b2442b0141844725f6906b70c1244b1567396be548535b6916c18a4dc9a01d137edbf63d
7
- data.tar.gz: 192d6dc9fe457cd124eeb240bd111d44bab696db7e414b1ef16f3ac10b5d979c6f50d08bd010986bcd7b8b86dea51d9eeb9fd2c8a02c8b7671fb0ec39692afbe
6
+ metadata.gz: e5a5f8b61ced5d7adfea0e6944c8ebd3d2aeaa6d637d50b2361bd194bc10c5b02efc745b4664770a0792b5408644324dd44d68d44b199e4d08d1b818335743f1
7
+ data.tar.gz: c118b9650c409c848e6c8822a795e011d22c6c1eeb2dba9c70f240f8509b65bd3b5571446730ca5e68e2f72397ce92c6b57315e834300296d39546129b3bd498
@@ -14,18 +14,46 @@ module Ibrain
14
14
  def execute
15
15
  query, variables, operation_name = normalize_entity
16
16
 
17
- result = schema.execute(
18
- query,
19
- variables: variables,
20
- context: {
21
- session: session,
22
- current_user: try_ibrain_current_user,
23
- controller: self,
24
- request: request
25
- },
26
- operation_name: operation_name,
27
- max_depth: max_depth(operation_name)
28
- )
17
+ is_mutation = query =~ /mutation #{operation_name}/
18
+ cache_key = "graphql-#{try_ibrain_current_user&.id}/#{request.headers.hash}-#{params.to_unsafe_h.hash}"
19
+ context = {
20
+ session: session,
21
+ current_user: try_ibrain_current_user,
22
+ controller: self,
23
+ request: request
24
+ }
25
+
26
+ exec_function = proc do |options|
27
+ schema.execute(
28
+ options[:query],
29
+ variables: options[:variables],
30
+ context: options[:context],
31
+ operation_name: options[:operation_name],
32
+ max_depth: options[:max_depth]
33
+ )
34
+ end
35
+
36
+ if is_mutation
37
+ result = exec_function.call({
38
+ query: query,
39
+ variables: variables,
40
+ context: context,
41
+ operation_name: operation_name,
42
+ max_depth: max_depth(operation_name)
43
+ })
44
+ else
45
+ result = Rails.cache.fetch(cache_key, expires_in: 10.minutes) do
46
+ result = exec_function.call({
47
+ query: query,
48
+ variables: variables,
49
+ context: context,
50
+ operation_name: operation_name,
51
+ max_depth: max_depth(operation_name)
52
+ })
53
+
54
+ result.to_h
55
+ end
56
+ end
29
57
 
30
58
  render_json_ok(result['data'], nil, result['errors'])
31
59
  end
@@ -4,7 +4,7 @@ module Ibrain
4
4
  module Extentions
5
5
  class ActiveRequired < GraphQL::Schema::FieldExtension
6
6
  def resolve(object:, arguments:, **rest)
7
- raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.session.is_deactivated') if is_inactivated(object)
7
+ raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.session.is_deactivated') unless is_activated(object)
8
8
 
9
9
  # yield the current time as `memo`
10
10
  yield(object, arguments, rest)
@@ -12,7 +12,7 @@ module Ibrain
12
12
 
13
13
  private
14
14
 
15
- def is_inactivated(object)
15
+ def is_activated(object)
16
16
  current_user = object.try(:context).try(:fetch, :current_user, nil)
17
17
  current_user.try(:is_activated?)
18
18
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibrain
4
- VERSION = "0.5.10"
4
+ VERSION = "0.5.13"
5
5
 
6
6
  def self.ibrain_version
7
7
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibrain-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store