Module: Eco::API::UseCases::GraphQL::Helpers::Location::Command::EndPoints::Optimizations

Included in:
Eco::API::UseCases::GraphQL::Helpers::Location::Command::EndPoints
Defined in:
lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb

Constant Summary collapse

DEFAULT_COMMANDS_PER_PAGE =
45

Instance Method Summary collapse

Instance Method Details

#commands_payload_without_structure_blockObject

Note:

this servces the purpose of optimizing/speeding up the requests.

Commands payload without querying Structure



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb', line 48

def commands_payload_without_structure_block
  proc {
    clientMutationId
    ok
    errors { # rubocop:disable Style/BlockDelimiters

      details
      fullMessages
      messages
    }
    draft { # rubocop:disable Style/BlockDelimiters

      ___Ecoportal__API__GraphQL__Fragment__LocationDraft
    }
  }
end

#commands_per_pageObject

Prevents each request from timing out



33
34
35
36
37
38
39
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb', line 33

def commands_per_page
  if self.class.const_defined?(:COMMANDS_PER_PAGE)
    self.class::COMMANDS_PER_PAGE
  else
    DEFAULT_COMMANDS_PER_PAGE
  end
end

#default_tree_tracking_modeSymbol

Available options are:

  • :per_request -> on each request
  • :per_batch -> at the end of each batch / stage (on last page)
  • :once -> only when the script starts to run

Returns:

  • (Symbol)

    the default tree tracking mode



11
12
13
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb', line 11

def default_tree_tracking_mode
  :per_request # :per_batch @todo per batch/stage is more plausible

end

#force_continue?Boolean

Whether to stop or continue on command fail

Returns:

  • (Boolean)


42
43
44
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb', line 42

def force_continue?
  false
end

#scope_commands_block(track_tree_mode: default_tree_tracking_mode) ⇒ Proc, NilClass

Note:
  1. Gives flexibility on at what time the structure should be retrieved
  2. This increases performacne, as we don't retrieve the full tree on each request unless necessary/specified
  3. nil falls the block back to the ecoportal-api-graphql gem, which has a default block that retrieves the structure

Helper to identify the commands payload block

Returns:

  • (Proc, NilClass)

    the payload block



23
24
25
26
27
28
29
30
# File 'lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb', line 23

def scope_commands_block(track_tree_mode: default_tree_tracking_mode)
  case track_tree_mode
  when :per_request
    nil
  when :once, :per_batch
    commands_payload_without_structure_block
  end
end