accelerate!

This commit is contained in:
BoHung Chiu 2021-10-10 17:35:14 +08:00
parent 0b3084bcd1
commit a8c015f3e5
1 changed files with 25 additions and 27 deletions

View File

@ -171,31 +171,27 @@ class AnnouncementsController < ApplicationController
end end
cats = cats.uniq cats = cats.uniq
tags = tags.uniq tags = tags.uniq
tags_translations = tags.map{|tag_id| tags_translations = Tag.where(:id.in=>tags).map{|t| [t.id.to_s,t.name]}
if tag_id == "all" if tags.include?("all")
t = I18n.t(:all) tags_translations = ["all",I18n.t(:all)] + tags_translations
else
t = Tag.find(tag_id).name rescue ""
end end
[tag_id,t] tags_translations = tags_translations.to_h
}.to_h cats_translations = Category.where(:id.in=>cats).map{|c| [c.id.to_s,c.title]}
cats_translations = cats.map{|cat_id| if cats.include?("all")
if cat_id == "all" cats_translations = ["all",I18n.t(:all)] + cats_translations
t = I18n.t(:all)
else
t = Category.find(cat_id).title rescue ""
end end
[cat_id,t] cats_translations = cats_translations.to_h
}.to_h
cats_relations = cats_translations.map{|cat_id,t| cats_relations = cats_translations.map{|cat_id,t|
if cat_id == "all" if cat_id == "all"
t = "all" t = "all"
end end
[cat_id,t] [cat_id,t]
}.to_h }.to_h
home_page = Page.first home_page = subpart.page_part.page rescue Page.first
page = nil page_url = (subpart.get_read_more_page_url rescue nil)
locale = I18n.locale.to_s locale = I18n.locale.to_s
if page_url.nil?
page = nil
if home_page.respond_to?(:find_page) if home_page.respond_to?(:find_page)
page = home_page.find_page(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil page = home_page.find_page(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
page = home_page.find_page(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil? page = home_page.find_page(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
@ -203,6 +199,8 @@ class AnnouncementsController < ApplicationController
page = Page.where(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil page = Page.where(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
page = Page.where(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil? page = Page.where(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
end end
page_url = page.get_url
end
all_cats = cats.dup all_cats = cats.dup
all_cats.delete "all" all_cats.delete "all"
if all_cats.count == 0 if all_cats.count == 0
@ -219,7 +217,7 @@ class AnnouncementsController < ApplicationController
"<div style=\"clear: both;\"></div>" + "<div style=\"clear: both;\"></div>" +
"<ul class=\"nav_tabs_filter\">" + "<ul class=\"nav_tabs_filter\">" +
(use_tag ? tags.map.with_index{|tag,i| (use_tag ? tags.map.with_index{|tag,i|
read_more_url = "/#{locale + page.url}" rescue "" read_more_url = "/#{locale + page_url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>(tag == 'all' ? all_tags : [tag])}.to_param if read_more_url != "" read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>(tag == 'all' ? all_tags : [tag])}.to_param if read_more_url != ""
read_more_text = I18n.t("announcement.more") read_more_text = I18n.t("announcement.more")
if tag != "all" if tag != "all"
@ -231,7 +229,7 @@ class AnnouncementsController < ApplicationController
end end
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(tag == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-tags=\"#{tag}\">#{tags_translations[tag]}</li>" "<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(tag == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-tags=\"#{tag}\">#{tags_translations[tag]}</li>"
}.join("") : cats.map.with_index{|cat,i| }.join("") : cats.map.with_index{|cat,i|
read_more_url = "/#{locale + page.url}" rescue "" read_more_url = "/#{locale + page_url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != "" read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != ""
read_more_text = I18n.t("announcement.more") read_more_text = I18n.t("announcement.more")
if cat != "all" if cat != "all"
@ -374,7 +372,7 @@ class AnnouncementsController < ApplicationController
" "
end end
if @tab_option == 0 if @tab_option == 0
read_more_url = "/#{locale + page.url}" rescue "" read_more_url = "/#{locale + page_url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>all_tags}.to_param if read_more_url != "" read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>all_tags}.to_param if read_more_url != ""
extra_after_html += " extra_after_html += "
<script> <script>