Class: Avo::Services::DebugService
- Inherits:
-
Object
- Object
- Avo::Services::DebugService
- Defined in:
- lib/avo/services/debug_service.rb
Class Method Summary collapse
- .avo_metadata ⇒ Object
- .cache_operational? ⇒ Boolean
- .config_metadata ⇒ Object
- .debug_report(request = nil) ⇒ Object
- .get_thread_count ⇒ Object
- .other_metadata(type = :actions, resources: []) ⇒ Object
Class Method Details
.avo_metadata ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/avo/services/debug_service.rb', line 33 def resource_classes = Avo.resource_manager.all dashboards = defined?(Avo::Dashboards) ? Avo::Dashboards.dashboard_manager.all : [] resources = resource_classes.map do |resource_class| resource = resource_class.new view: :index resource.detect_fields resource end field_definitions = resources.map(&:get_field_definitions) fields_count = field_definitions.map(&:count).sum fields_per_resource = sprintf("%0.01f", fields_count / (resources.count + 0.0)).to_f field_types = {} custom_fields_count = 0 field_definitions.each do |fields| fields.each do |field| field_types[field.type] ||= 0 field_types[field.type] += 1 custom_fields_count += 1 if field.custom? end end { resources_count: resources.count, dashboards_count: dashboards.count, fields_count:, fields_per_resource:, custom_fields_count:, field_types:, **(:actions, resources:), **(:filters, resources:), main_menu_present: Avo.configuration..present?, profile_menu_present: Avo.configuration..present?, cache_store: Avo.cache_store&.class&.to_s, cache_operational: cache_operational?, ** } rescue => error { error: "Failed to generate the Avo metadata", error_message: error. } end |
.cache_operational? ⇒ Boolean
78 79 80 81 82 83 84 85 |
# File 'lib/avo/services/debug_service.rb', line 78 def cache_operational? Avo.cache_store.write("avo-test-cache", "test_value") operational = Avo.cache_store.read("avo-test-cache") == "test_value" Avo.cache_store.delete("avo-test-cache") operational rescue => error "error: #{error.}" end |
.config_metadata ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/avo/services/debug_service.rb', line 98 def { config: { root_path: Avo.configuration.root_path, app_name: Avo.configuration.app_name } } end |
.debug_report(request = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/avo/services/debug_service.rb', line 3 def debug_report(request = nil) payload = {} hq = Avo::Licensing::HQ.new(request) payload[:license_id] = Avo::Current&.license&.id payload[:license_valid] = Avo::Current&.license&.valid? payload[:license_payload] = Avo::Current&.license&.payload payload[:license_response] = Avo::Current&.license&.response payload[:hq_payload] = hq&.payload payload[:thread_count] = get_thread_count payload[:license_abilities] = Avo::Current&.license&.abilities payload[:cache_store] = Avo.cache_store&.class&.to_s payload[:avo_metadata] = payload[:app_timezone] = Time.current.zone payload[:cache_key] = Avo::Licensing::HQ.cache_key payload[:cache_key_contents] = hq&.cached_response payload[:plugins] = Avo.plugin_manager.as_json payload rescue => e e. end |
.get_thread_count ⇒ Object
27 28 29 30 31 |
# File 'lib/avo/services/debug_service.rb', line 27 def get_thread_count Thread.list.count { |thread| thread.status == "run" } rescue => e e end |
.other_metadata(type = :actions, resources: []) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/avo/services/debug_service.rb', line 87 def (type = :actions, resources: []) types = resources.map(&:"get_#{type}") type_count = types.flatten.uniq.count type_per_resource = sprintf("%0.01f", types.map(&:count).sum / (resources.count + 0.0)) { "#{type}_count": type_count, "#{type}_per_resource": type_per_resource } end |