Skip to content

Commit

Permalink
performance: perf optimizations (#2954)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Jul 7, 2024
1 parent cea161b commit d88f603
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

![](./public/avo-assets/logo-on-white.png)

**<a href="https://avohq.io" title="Rails Admin Panel Framework">Avo - Ruby on Rails admin panel framework</a>**
**<a href="https://avohq.io" title="Ruby on Rails Admin Panel Framework">Avo - Ruby on Rails Admin Panel Framework</a>**

Avo is a very custom Admin Panel Framework, Content Management System, and Internal Tool Builder for Ruby on Rails that saves engineers and teams **months of development time**.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% if file.present? %>
<div class="flex flex-col h-full">
<% if file.representable? && is_image? %>
<%= image_tag helpers.main_app.url_for(file), class: "rounded-lg max-w-full self-start #{@extra_classes}" %>
<%= image_tag helpers.main_app.url_for(file), class: "rounded-lg max-w-full self-start #{@extra_classes}", loading: :lazy, width: file.metadata["width"], height: file.metadata["height"] %>
<% elsif is_audio? %>
<%= audio_tag(helpers.main_app.url_for(file), controls: true, preload: false, class: 'w-full') %>
<% elsif is_video? %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="absolute bg-gray-50 w-full h-full">
<%= image_tag Avo.configuration.branding.placeholder, class: 'relative transform -translate-x-1/2 -translate-y-1/2 h-20 text-gray-400 inset-auto top-1/2 left-1/2' %>
<%= image_tag Avo.configuration.branding.placeholder, class: "relative transform -translate-x-1/2 -translate-y-1/2 h-20 text-gray-400 inset-auto top-1/2 left-1/2", loading: :lazy %>
</div>
2 changes: 1 addition & 1 deletion app/components/avo/index/grid_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def render_cover
def link_to_cover
classes = "absolute h-full w-full object-cover"

link_to image_tag(@card[:cover_url], class: classes), resource_view_path, class: classes, title: @card[:title]
link_to image_tag(@card[:cover_url], class: classes), resource_view_path, class: classes, title: @card[:title], loading: :lazy, width: "640", height: "480"
end

def render_title
Expand Down
11 changes: 7 additions & 4 deletions lib/avo/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ def model_class(record_class: nil)
# With uncountable models route key appends an _index suffix (Fish->fish_index)
# Example: User->users, MediaItem->media_items, Fish->fish
def model_key
model_class.model_name.plural
@model_key ||= model_class.model_name.plural
end

def class_name
to_s.demodulize
@class_name ||= to_s.demodulize
end

def route_key
Expand All @@ -170,7 +170,7 @@ def translation_key
end

def name
name_from_translation_key(count: 1, default: class_name.underscore.humanize)
@name ||= name_from_translation_key(count: 1, default: class_name.underscore.humanize)
end
alias_method :singular_name, :name

Expand Down Expand Up @@ -448,7 +448,6 @@ def authorization(user: nil)
def file_hash
content_to_be_hashed = ""

file_name = self.class.underscore_name.tr(" ", "_")
resource_path = Rails.root.join("app", "avo", "resources", "#{file_name}.rb").to_s
if File.file? resource_path
content_to_be_hashed += File.read(resource_path)
Expand All @@ -463,6 +462,10 @@ def file_hash
Digest::MD5.hexdigest(content_to_be_hashed)
end

def file_name
@file_name ||= self.class.underscore_name.tr(" ", "_")
end

def cache_hash(parent_record)
result = [record, file_hash]

Expand Down
2 changes: 1 addition & 1 deletion lib/avo/fields/base_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def record_errors
end

def type
self.class.name.demodulize.to_s.underscore.gsub("_field", "")
@type ||= self.class.name.demodulize.to_s.underscore.gsub("_field", "")
end

def custom?
Expand Down

0 comments on commit d88f603

Please sign in to comment.