accelerate speed

This commit is contained in:
chiu 2021-11-08 15:11:18 +00:00
parent 52af999549
commit ec834f143b
1 changed files with 17 additions and 9 deletions

View File

@ -181,7 +181,13 @@ class GalleriesController < ApplicationController
def widget
@album_setting = AlbumSetting.first
tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags
album_ids = Album.filter_by_widget_categories(OrbitHelper.widget_categories,false).filter_by_tags(tags).pluck(:id)
albums = Album.filter_by_widget_categories(OrbitHelper.widget_categories,false).filter_by_tags(tags).to_a
album_ids = []
albums_map = {}
albums.each do |ab|
album_ids << ab.id
albums_map[ab.id] = ab
end
album_color_map = AlbumColor.where(:album_id.in=> album_ids).pluck(:album_id,:color,:album_card_background_color,:album_card_text_color).map{|v| [v[0],v[1..-1]]}.to_h
params = OrbitHelper.params
counts = OrbitHelper.widget_data_count
@ -189,18 +195,20 @@ class GalleriesController < ApplicationController
images = images.each_with_index.collect do |a,i|
colors = album_color_map[a.album_id]
alt_text = (a.description.blank? ? "gallery image" : Nokogiri::HTML(a.description).text().strip)
f = a.file
ab = albums_map[a.album_id]
{
"link_text" => "",
"link_to_show" => OrbitHelper.widget_more_url + "/" + a.album.to_param + "#" + a.id.to_s,
"link_to_show" => OrbitHelper.widget_more_url + "/" + ab.to_param + "#" + a.id.to_s,
"alt_title" => alt_text,
"src" => a.file.url,
"thumb-src" => a.file.thumb.url,
"thumb-large-src" => a.file.thumb_large.url,
"src" => f.url,
"thumb-src" => f.thumb.url,
"thumb-large-src" => f.thumb_large.url,
"image_description" => a.description,
"image_short_description" => a.title,
"mobile-src" => a.file.mobile.url,
"theater-src" => a.file.theater.url,
"album-name" => a.album.name_translations[I18n.locale],
"mobile-src" => f.mobile.url,
"theater-src" => f.theater.url,
"album-name" => ab.name_translations[I18n.locale],
"album_color" => iterate_data(colors[1],colors[0],@album_setting.album_card_background_color,'transparent'),
"album_card_text_color" => iterate_data(colors[2],@album_setting.album_card_text_color),
"i" => i
@ -265,4 +273,4 @@ class GalleriesController < ApplicationController
end
flag
end
end
end