Adjust naming of user and model attributes
- Remove unnecessary attributes that cause additional SQL queries - Remove unneeded check for nil on current_item
This commit is contained in:
@@ -205,9 +205,9 @@ module ApplicationHelper
|
||||
def body_attributes(user = CurrentUser.user, current_item = nil)
|
||||
user_attributes = %i[id name level level_string theme] + User::BOOLEAN_ATTRIBUTES.map(&:to_sym)
|
||||
user_attributes += User::Roles.map { |role| :"is_#{role}?" }
|
||||
mapped_user_attributes = data_attributes_for(user, "user", user_attributes)
|
||||
mapped_user_attributes = data_attributes_for(user, "current-user", user_attributes)
|
||||
model_attributes = (!current_item.nil? ? (!current_item.id.nil? ? [:id] : [] ) + current_item.html_data_attributes : [])
|
||||
mapped_model_attributes = (!current_item.nil? ? data_attributes_for(current_item, "show", model_attributes) : {} )
|
||||
mapped_model_attributes = (!current_item.nil? ? data_attributes_for(current_item, current_item.model_name.singular.dasherize, model_attributes) : {} )
|
||||
all_mapped_attributes = mapped_user_attributes.merge(mapped_model_attributes)
|
||||
controller_param = params[:controller].parameterize.dasherize
|
||||
action_param = params[:action].parameterize.dasherize
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
let CurrentUser = {};
|
||||
|
||||
CurrentUser.data = function(key) {
|
||||
return $("body").data(`user-${key}`);
|
||||
return $("body").data(`current-user-${key}`);
|
||||
};
|
||||
|
||||
CurrentUser.update = function(settings) {
|
||||
|
||||
@@ -519,7 +519,7 @@ class Artist < ApplicationRecord
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id, [:wiki_page, :id]]
|
||||
[:creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:category_name, [:artist, :id]]
|
||||
[:category_name]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
<%= yield :html_header %>
|
||||
<%= raw Danbooru.config.custom_html_header_content %>
|
||||
</head>
|
||||
<%= tag.body **body_attributes(CurrentUser.user, (defined?(@current_item) ? @current_item : nil)) do %>
|
||||
<%= tag.body **body_attributes(CurrentUser.user, @current_item) do %>
|
||||
<%= render "news_updates/listing" %>
|
||||
|
||||
<header id="top">
|
||||
|
||||
Reference in New Issue
Block a user