accelerate speed

This commit is contained in:
邱博亞 2022-08-31 12:32:13 +08:00
parent 2c53177389
commit 12d35e0645
1 changed files with 242 additions and 238 deletions

View File

@ -13,7 +13,8 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t("category")
row1 << "select"
t = ""
categories = @module_app.categories.asc(:created_at)
categories = @module_app.categories.asc(:created_at).to_a
categories_ids_map = categories.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
categories.each_with_index do |cat,i|
t = t + "#{i}" + " -> " + cat.title + ", "
end
@ -27,7 +28,8 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t("tags")
row1 << "select"
t = ""
tags = @module_app.tags.asc(:created_at)
tags = @module_app.tags.asc(:created_at).to_a
tag_ids_map = tags.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
tags.each_with_index do |tag,i|
t = t + "#{i}" + " -> " + tag.name + ", "
end
@ -165,13 +167,15 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
sheet.add_row row, :style => heading
sheet.add_row row1
sheet.add_row row2, :style => example
tag_anns_map = Tagging.collection.aggregate([
{"$match" => {"taggable_id"=>{"$in"=>@event_news.pluck(:id)}}},
{"$group" => {"_id"=>"$taggable_id","children"=>{"$push"=>"$tag_id"}}}
]).map{|v| [v['_id'],v['children']]}.to_h
@event_news.each do |anns|
row = []
row << categories.to_a.index(anns.category)
t = []
anns.tags.each do |tag|
t << tags.to_a.index(tag)
row << categories_ids_map[anns.category_id]
t = Array(tag_anns_map[anns.id]).map do |tag_id|
tag_ids_map[tag_id]
end
row << t.join(",")
row << (anns.event_date.strftime("%Y/%m/%d %H:%M") rescue "")