mirror of
https://github.com/dpnmw/community-landing.git
synced 2026-03-18 09:27:16 +00:00
Admin log set to track crashing
This commit is contained in:
@@ -7,42 +7,57 @@ module CommunityLanding
|
|||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
# Top contributors
|
# Top contributors
|
||||||
data[:contributors] = if s.contributors_enabled
|
data[:contributors] = begin
|
||||||
User
|
if s.contributors_enabled
|
||||||
.joins(:posts)
|
User
|
||||||
.where(posts: { created_at: s.contributors_days.days.ago.. })
|
.joins(:posts)
|
||||||
.where.not(username: %w[system discobot])
|
.where(posts: { created_at: s.contributors_days.days.ago.. })
|
||||||
.where(active: true, staged: false)
|
.where.not(username: %w[system discobot])
|
||||||
.group("users.id")
|
.where(active: true, staged: false)
|
||||||
.order("COUNT(posts.id) DESC")
|
.group("users.id")
|
||||||
.limit(s.contributors_count)
|
.order("COUNT(posts.id) DESC")
|
||||||
.select("users.*, COUNT(posts.id) AS post_count")
|
.limit(s.contributors_count)
|
||||||
|
.select("users.*, COUNT(posts.id) AS post_count")
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.warn("[CommunityLanding] contributors fetch failed: #{e.message}")
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public groups — optionally filtered by selected names
|
# Public groups — optionally filtered by selected names
|
||||||
data[:groups] = if s.groups_enabled
|
data[:groups] = begin
|
||||||
selected = s.groups_selected.presence
|
if s.groups_enabled
|
||||||
scope = Group
|
selected = s.groups_selected.presence
|
||||||
.where(visibility_level: Group.visibility_levels[:public])
|
scope = Group
|
||||||
.where(automatic: false)
|
.where(visibility_level: Group.visibility_levels[:public])
|
||||||
|
.where(automatic: false)
|
||||||
|
|
||||||
if selected
|
if selected
|
||||||
names = selected.split("|").map(&:strip).reject(&:empty?)
|
names = selected.split("|").map(&:strip).reject(&:empty?)
|
||||||
scope = scope.where(name: names) if names.any?
|
scope = scope.where(name: names) if names.any?
|
||||||
|
end
|
||||||
|
|
||||||
|
scope.limit(s.groups_count)
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
scope.limit(s.groups_count)
|
Rails.logger.warn("[CommunityLanding] groups fetch failed: #{e.message}")
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Trending topics
|
# Trending topics
|
||||||
data[:topics] = if s.topics_enabled
|
data[:topics] = begin
|
||||||
Topic
|
if s.topics_enabled
|
||||||
.listable_topics
|
Topic
|
||||||
.where(visible: true)
|
.listable_topics
|
||||||
.where("topics.created_at > ?", 30.days.ago)
|
.where(visible: true)
|
||||||
.order(posts_count: :desc)
|
.where("topics.created_at > ?", 30.days.ago)
|
||||||
.limit(s.topics_count)
|
.order(posts_count: :desc)
|
||||||
.includes(:category, :user)
|
.limit(s.topics_count)
|
||||||
|
.includes(:category, :user)
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.warn("[CommunityLanding] topics fetch failed: #{e.message}")
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Aggregate stats
|
# Aggregate stats
|
||||||
@@ -53,13 +68,18 @@ module CommunityLanding
|
|||||||
chat_count = 0
|
chat_count = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
data[:stats] = {
|
data[:stats] = begin
|
||||||
members: User.real.count,
|
{
|
||||||
topics: Topic.listable_topics.count,
|
members: User.real.count,
|
||||||
posts: Post.where(user_deleted: false).count,
|
topics: Topic.listable_topics.count,
|
||||||
likes: Post.sum(:like_count),
|
posts: Post.where(user_deleted: false).count,
|
||||||
chats: chat_count,
|
likes: Post.sum(:like_count),
|
||||||
}
|
chats: chat_count,
|
||||||
|
}
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.warn("[CommunityLanding] stats fetch failed: #{e.message}")
|
||||||
|
{ members: 0, topics: 0, posts: 0, likes: 0, chats: 0 }
|
||||||
|
end
|
||||||
|
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ module CommunityLanding
|
|||||||
def render_hero
|
def render_hero
|
||||||
hero_card = @s.hero_card_enabled rescue true
|
hero_card = @s.hero_card_enabled rescue true
|
||||||
hero_img_first = @s.hero_image_first rescue false
|
hero_img_first = @s.hero_image_first rescue false
|
||||||
hero_bg_img = @s.hero_background_image_url.presence
|
hero_bg_img = (@s.hero_background_image_url.presence rescue nil)
|
||||||
hero_border = @s.hero_border_style rescue "none"
|
hero_border = @s.hero_border_style rescue "none"
|
||||||
hero_min_h = @s.hero_min_height rescue 0
|
hero_min_h = @s.hero_min_height rescue 0
|
||||||
site_name = @s.title
|
site_name = @s.title
|
||||||
@@ -197,7 +197,7 @@ module CommunityLanding
|
|||||||
html << "<div class=\"cl-hero__creators#{align_class}\">\n"
|
html << "<div class=\"cl-hero__creators#{align_class}\">\n"
|
||||||
html << "<h3 class=\"cl-hero__creators-title\">#{e(creators_title)}</h3>\n" if show_title
|
html << "<h3 class=\"cl-hero__creators-title\">#{e(creators_title)}</h3>\n" if show_title
|
||||||
top3.each_with_index do |user, idx|
|
top3.each_with_index do |user, idx|
|
||||||
avatar_url = user.avatar_template.gsub("{size}", "120")
|
avatar_url = user.avatar_template.to_s.gsub("{size}", "120")
|
||||||
activity_count = user.attributes["post_count"].to_i rescue 0
|
activity_count = user.attributes["post_count"].to_i rescue 0
|
||||||
rank_color = rank_colors[idx]
|
rank_color = rank_colors[idx]
|
||||||
count_prefix = show_count_label && count_label.present? ? "#{e(count_label)} " : ""
|
count_prefix = show_count_label && count_label.present? ? "#{e(count_label)} " : ""
|
||||||
@@ -217,8 +217,8 @@ module CommunityLanding
|
|||||||
|
|
||||||
html << "</div>\n"
|
html << "</div>\n"
|
||||||
|
|
||||||
hero_image_urls_raw = @s.hero_image_urls.presence
|
hero_image_urls_raw = (@s.hero_image_urls.presence rescue nil)
|
||||||
hero_video = @s.hero_video_url.presence rescue nil
|
hero_video = (@s.hero_video_url.presence rescue nil)
|
||||||
blur_attr = (@s.hero_video_blur_on_hover rescue true) ? " data-blur-hover=\"true\"" : ""
|
blur_attr = (@s.hero_video_blur_on_hover rescue true) ? " data-blur-hover=\"true\"" : ""
|
||||||
has_images = false
|
has_images = false
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ module CommunityLanding
|
|||||||
|
|
||||||
# CSS custom properties for accent colors, gradients, backgrounds
|
# CSS custom properties for accent colors, gradients, backgrounds
|
||||||
def color_overrides
|
def color_overrides
|
||||||
accent = hex(@s.accent_color) || "#d4a24e"
|
accent = (hex(@s.accent_color) rescue nil) || "#d4a24e"
|
||||||
accent_hover = hex(@s.accent_hover_color) || "#c4922e"
|
accent_hover = (hex(@s.accent_hover_color) rescue nil) || "#c4922e"
|
||||||
dark_bg = hex(@s.dark_bg_color) || "#06060f"
|
dark_bg = (hex(@s.dark_bg_color) rescue nil) || "#06060f"
|
||||||
light_bg = hex(@s.light_bg_color) || "#faf6f0"
|
light_bg = (hex(@s.light_bg_color) rescue nil) || "#faf6f0"
|
||||||
stat_icon = hex(@s.stat_icon_color) || accent
|
stat_icon = (hex(@s.stat_icon_color) rescue nil) || accent
|
||||||
about_bg_img = @s.about_background_image_url.presence
|
about_bg_img = (@s.about_background_image_url.presence rescue nil)
|
||||||
app_g1 = hex(@s.app_cta_gradient_start) || accent
|
app_g1 = (hex(@s.app_cta_gradient_start) rescue nil) || accent
|
||||||
app_g2 = hex(@s.app_cta_gradient_mid) || accent_hover
|
app_g2 = (hex(@s.app_cta_gradient_mid) rescue nil) || accent_hover
|
||||||
app_g3 = hex(@s.app_cta_gradient_end) || accent_hover
|
app_g3 = (hex(@s.app_cta_gradient_end) rescue nil) || accent_hover
|
||||||
stat_icon_bg = hex(@s.stat_icon_bg_color.presence) rescue nil
|
stat_icon_bg = hex(@s.stat_icon_bg_color.presence) rescue nil
|
||||||
stat_counter = hex(@s.stat_counter_color.presence) rescue nil
|
stat_counter = hex(@s.stat_counter_color.presence) rescue nil
|
||||||
video_btn_bg = hex(@s.hero_video_button_color.presence) rescue nil
|
video_btn_bg = hex(@s.hero_video_button_color.presence) rescue nil
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ after_initialize do
|
|||||||
response.headers["Content-Security-Policy"] = csp
|
response.headers["Content-Security-Policy"] = csp
|
||||||
|
|
||||||
render html: html.html_safe, layout: false, content_type: "text/html"
|
render html: html.html_safe, layout: false, content_type: "text/html"
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.error("[CommunityLanding] 500 error: #{e.class}: #{e.message}\n#{e.backtrace&.first(10)&.join("\n")}")
|
||||||
|
render html: "<!-- CommunityLanding error: #{ERB::Util.html_escape(e.class)}: #{ERB::Util.html_escape(e.message)} -->".html_safe,
|
||||||
|
layout: false, content_type: "text/html", status: 500
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
Reference in New Issue
Block a user