Skip to content

Commit

Permalink
chore: fix cache store display (#3370)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Nov 1, 2024
1 parent 08269fc commit 06081ae
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
12 changes: 3 additions & 9 deletions app/views/avo/debug/status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
(<%= time_ago_in_words license.response['fetched_at'] %> ago)</dd>
<% end %>
<dt class="font-semibold text-sm">Cache store</dt>
<dd>
<%= Avo.cache_store.class %>
</dd>
</dl>
</div>
</div>
Expand All @@ -82,15 +85,6 @@
</div>
</div>
</div>
<%= render Avo::PanelComponent.new(title: "Report") do |c| %>
<% c.with_body do %>
<div class="p-4">
<turbo-frame id="debug-report" src="<%= root_path %>avo_private/debug/report" target="_top" class="block">
Loading...
</turbo-frame>
</div>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
Expand Down
14 changes: 10 additions & 4 deletions lib/avo/licensing/h_q.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ def payload
app_name: app_name
}

# metadata = Avo::Services::DebugService.avo_metadata
# if metadata[:resources_count] != 0
# result[:avo_metadata] = "metadata"
# end
begin
metadata = Avo::Services::DebugService.avo_metadata
rescue => error
metadata = {
error_message: error.message,
error: "Failed to generate the Avo metadata"
}
end

result[:avo_metadata] = metadata

result
end
Expand Down
60 changes: 32 additions & 28 deletions lib/avo/services/debug_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def debug_report(request = nil)
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
payload[:plugins] = Avo.plugin_manager.as_json

payload
rescue => e
e
e.message
end

def get_thread_count
Expand All @@ -31,46 +31,50 @@ def get_thread_count
end

def avo_metadata
resources = Avo.resource_manager.all
resource_classes = Avo.resource_manager.all
dashboards = defined?(Avo::Dashboards) ? Avo::Dashboards.dashboard_manager.all : []
# 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))
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
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
custom_fields_count += 1 if field.custom?
end
end

{
resources_count: resources.count,
dashboards_count: dashboards.count,
# fields_count: fields_count,
# fields_per_resource: fields_per_resource,
# custom_fields_count: custom_fields_count,
# field_types: field_types,
# **other_metadata(:actions), # TODO: this is fetching actions without hydration
# **other_metadata(:filters),
fields_count:,
fields_per_resource:,
custom_fields_count:,
field_types:,
**other_metadata(:actions, resources:),
**other_metadata(:filters, resources:),
main_menu_present: Avo.configuration.main_menu.present?,
profile_menu_present: Avo.configuration.profile_menu.present?,
cache_store: Avo.cache_store&.class&.to_s,
**config_metadata
}
# rescue => error
# {
# error: error.message
# }
rescue => error
{
error: "Failed to generate the Avo metadata",
error_message: error.message
}
end

def other_metadata(type = :actions)
resources = Avo.resource_manager.all

def other_metadata(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))
Expand Down

0 comments on commit 06081ae

Please sign in to comment.