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

@ -1,239 +1,243 @@
# encoding: utf-8 # encoding: utf-8
wb = xlsx_package.workbook wb = xlsx_package.workbook
wb.add_worksheet(name: "EventNewsModule") do |sheet| wb.add_worksheet(name: "EventNewsModule") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true) heading = sheet.styles.add_style(:b => true, :locked => true)
example = sheet.styles.add_style(:i => true) example = sheet.styles.add_style(:i => true)
row = [] row = []
row1 = [] row1 = []
row2 = [] row2 = []
row << t("category") row << t("category")
row1 << "select" row1 << "select"
t = "" t = ""
categories = @module_app.categories.asc(:created_at) categories = @module_app.categories.asc(:created_at).to_a
categories.each_with_index do |cat,i| categories_ids_map = categories.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
t = t + "#{i}" + " -> " + cat.title + ", " categories.each_with_index do |cat,i|
end t = t + "#{i}" + " -> " + cat.title + ", "
if categories.count > 0 end
t = t + " Example : 0" if categories.count > 0
else t = t + " Example : 0"
t = "Leave this field blank" else
end t = "Leave this field blank"
row2 << t end
row2 << t
row << t("tags")
row1 << "select" row << t("tags")
t = "" row1 << "select"
tags = @module_app.tags.asc(:created_at) t = ""
tags.each_with_index do |tag,i| tags = @module_app.tags.asc(:created_at).to_a
t = t + "#{i}" + " -> " + tag.name + ", " tag_ids_map = tags.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
end tags.each_with_index do |tag,i|
if tags.count > 0 t = t + "#{i}" + " -> " + tag.name + ", "
t = t + " Example : 0,1,2" end
else if tags.count > 0
t = "Leave this field blank" t = t + " Example : 0,1,2"
end else
row2 << t t = "Leave this field blank"
end
row << t("event_news.event_date") row2 << t
row1 << "datetime"
row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20" row << t("event_news.event_date")
row1 << "datetime"
row << t("event_news.start_date") row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20"
row1 << "datetime"
row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:30" row << t("event_news.start_date")
row1 << "datetime"
row << t("event_news.end_date") row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:30"
row1 << "datetime"
row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/12 17:30" row << t("event_news.end_date")
row1 << "datetime"
row << t("top") row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/12 17:30"
row1 << "boolean"
row2 << "0 for false, 1 for true" row << t("top")
row1 << "boolean"
row << t("hot") row2 << "0 for false, 1 for true"
row1 << "boolean"
row2 << "0 for false, 1 for true" row << t("hot")
row1 << "boolean"
row << t("hide") row2 << "0 for false, 1 for true"
row1 << "boolean"
row2 << "0 for false, 1 for true " row << t("hide")
row1 << "boolean"
row << t("image") row2 << "0 for false, 1 for true "
row1 << "url"
row2 << "http://www.example.com/images/example.png" row << t("image")
row1 << "url"
row << t("image") + " " + t("description") + " - " + t("en") row2 << "http://www.example.com/images/example.png"
row1 << "textfield"
row2 << "" row << t("image") + " " + t("description") + " - " + t("en")
row << t("image") + " " + t("description") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << ""
row2 << "" row << t("image") + " " + t("description") + " - " + t("zh_tw")
row1 << "textfield"
row << t("title") + " - " + t("en") row2 << ""
row1 << "textfield"
row2 << "" row << t("title") + " - " + t("en")
row << t("title") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << ""
row2 << "" row << t("title") + " - " + t("zh_tw")
row1 << "textfield"
row << t("event_news.speaker") + " - " + t("en") row2 << ""
row1 << "textfield"
row2 << "" row << t("event_news.speaker") + " - " + t("en")
row << t("event_news.speaker") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << ""
row2 << "" row << t("event_news.speaker") + " - " + t("zh_tw")
row1 << "textfield"
row << t("event_news.host") + " - " + t("en") row2 << ""
row1 << "textfield"
row2 << "" row << t("event_news.host") + " - " + t("en")
row << t("event_news.host") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << ""
row2 << "" row << t("event_news.host") + " - " + t("zh_tw")
row1 << "textfield"
row << t("subtitle") + " - " + t("en") row2 << ""
row1 << "textarea"
row2 << "" row << t("subtitle") + " - " + t("en")
row << t("subtitle") + " - " + t("zh_tw") row1 << "textarea"
row1 << "textarea" row2 << ""
row2 << "" row << t("subtitle") + " - " + t("zh_tw")
row1 << "textarea"
row << t("content") + " - " + t("en") row2 << ""
row1 << "editor"
row2 << "" row << t("content") + " - " + t("en")
row << t("content") + " - " + t("zh_tw") row1 << "editor"
row1 << "editor" row2 << ""
row2 << "" row << t("content") + " - " + t("zh_tw")
row1 << "editor"
row << t("event_news.notes") + " - " + t("en") row2 << ""
row1 << "editor"
row2 << "" row << t("event_news.notes") + " - " + t("en")
row << t("event_news.notes") + " - " + t("zh_tw") row1 << "editor"
row1 << "editor" row2 << ""
row2 << "" row << t("event_news.notes") + " - " + t("zh_tw")
row1 << "editor"
row << t("link") row2 << ""
row1 << "textfield"
row2 << "Seperate with ';'. Example: http://rulingcom.com; http://google.com" row << t("link")
row1 << "textfield"
row << t("link") + " " + t("url_alt") + " - " + t("en") row2 << "Seperate with ';'. Example: http://rulingcom.com; http://google.com"
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine" row << t("link") + " " + t("url_alt") + " - " + t("en")
row << t("link") + " " + t("url_alt") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine" row << t("link") + " " + t("url_alt") + " - " + t("zh_tw")
row1 << "textfield"
row << t("file_") row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
row1 << "textfield"
row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png" row << t("file_")
row1 << "textfield"
row << t("file_") + " " + t("description") + " - " + t("en") row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait" row << t("file_") + " " + t("description") + " - " + t("en")
row << t("file_") + " " + t("description") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait" row << t("file_") + " " + t("description") + " - " + t("zh_tw")
row1 << "textfield"
row << t("file_") + " " + t("alternative") + " - " + t("en") row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2" row << t("file_") + " " + t("alternative") + " - " + t("en")
row << t("file_") + " " + t("alternative") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2" row << t("file_") + " " + t("alternative") + " - " + t("zh_tw")
row1 << "textfield"
row << t("event_news.place") + "-" + t("en") row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
row1 << "textfield"
row2 << "" row << t("event_news.place") + "-" + t("en")
row << t("event_news.place") + "-" + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << ""
row2 << "" row << t("event_news.place") + "-" + t("zh_tw")
row << t("event_news.event_end_date") row1 << "textfield"
row1 << "datetime" row2 << ""
row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20" row << t("event_news.event_end_date")
row << t("event_news.carousel_image") + "-" + t("image") row1 << "datetime"
row1 << "url" row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20"
row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png" row << t("event_news.carousel_image") + "-" + t("image")
row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("en") row1 << "url"
row1 << "textfield" row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait" row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("en")
row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("zh_tw") row1 << "textfield"
row1 << "textfield" row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait" row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("zh_tw")
sheet.add_row row, :style => heading row1 << "textfield"
sheet.add_row row1 row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
sheet.add_row row2, :style => example sheet.add_row row, :style => heading
sheet.add_row row1
@event_news.each do |anns| sheet.add_row row2, :style => example
row = [] tag_anns_map = Tagging.collection.aggregate([
row << categories.to_a.index(anns.category) {"$match" => {"taggable_id"=>{"$in"=>@event_news.pluck(:id)}}},
t = [] {"$group" => {"_id"=>"$taggable_id","children"=>{"$push"=>"$tag_id"}}}
anns.tags.each do |tag| ]).map{|v| [v['_id'],v['children']]}.to_h
t << tags.to_a.index(tag) @event_news.each do |anns|
end row = []
row << t.join(",") row << categories_ids_map[anns.category_id]
row << (anns.event_date.strftime("%Y/%m/%d %H:%M") rescue "") t = Array(tag_anns_map[anns.id]).map do |tag_id|
row << (anns.postdate.strftime("%Y/%m/%d %H:%M") rescue "") tag_ids_map[tag_id]
row << (anns.deadline.strftime("%Y/%m/%d %H:%M") rescue "") end
row << (anns.is_top? ? 1 : 0) row << t.join(",")
row << (anns.is_hot? ? 1 : 0) row << (anns.event_date.strftime("%Y/%m/%d %H:%M") rescue "")
row << (anns.is_hidden? ? 1 : 0) row << (anns.postdate.strftime("%Y/%m/%d %H:%M") rescue "")
row << ("http://" + request.host_with_port + anns.image.url rescue "") row << (anns.deadline.strftime("%Y/%m/%d %H:%M") rescue "")
row << anns.image_description_translations["en"] row << (anns.is_top? ? 1 : 0)
row << anns.image_description_translations["zh_tw"] row << (anns.is_hot? ? 1 : 0)
row << anns.title_translations["en"] row << (anns.is_hidden? ? 1 : 0)
row << anns.title_translations["zh_tw"] row << ("http://" + request.host_with_port + anns.image.url rescue "")
row << anns.speaker_translations["en"] row << anns.image_description_translations["en"]
row << anns.speaker_translations["zh_tw"] row << anns.image_description_translations["zh_tw"]
row << anns.host_translations["en"] row << anns.title_translations["en"]
row << anns.host_translations["zh_tw"] row << anns.title_translations["zh_tw"]
row << anns.subtitle_translations["en"] row << anns.speaker_translations["en"]
row << anns.subtitle_translations["zh_tw"] row << anns.speaker_translations["zh_tw"]
row << anns.text_translations["en"] row << anns.host_translations["en"]
row << anns.text_translations["zh_tw"] row << anns.host_translations["zh_tw"]
row << anns.notes_translations["en"] row << anns.subtitle_translations["en"]
row << anns.notes_translations["zh_tw"] row << anns.subtitle_translations["zh_tw"]
row << anns.text_translations["en"]
links = anns.event_news_links.asc(:created_at) row << anns.text_translations["zh_tw"]
t = links.collect{|l|l.url} row << anns.notes_translations["en"]
row << t.join(";") row << anns.notes_translations["zh_tw"]
t = links.collect{|l|l.title_translations["en"]}
row << t.join(";") links = anns.event_news_links.asc(:created_at)
t = links.collect{|l|l.title_translations["zh_tw"]} t = links.collect{|l|l.url}
row << t.join(";") row << t.join(";")
t = links.collect{|l|l.title_translations["en"]}
files = anns.event_news_files.asc(:created_at) row << t.join(";")
t = files.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)} t = links.collect{|l|l.title_translations["zh_tw"]}
t.delete(nil) row << t.join(";")
row << t.join(";")
t = files.collect{|l|l.description_translations["en"]} files = anns.event_news_files.asc(:created_at)
row << t.join(";") t = files.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
t = files.collect{|l|l.description_translations["zh_tw"]} t.delete(nil)
row << t.join(";") row << t.join(";")
t = files.collect{|l|l.title_translations["en"]} t = files.collect{|l|l.description_translations["en"]}
row << t.join(";") row << t.join(";")
t = files.collect{|l|l.title_translations["zh_tw"]} t = files.collect{|l|l.description_translations["zh_tw"]}
row << t.join(";") row << t.join(";")
row << anns.place_translations["en"] t = files.collect{|l|l.title_translations["en"]}
row << anns.place_translations["zh_tw"] row << t.join(";")
t = files.collect{|l|l.title_translations["zh_tw"]}
row << (anns.event_end_date.strftime("%Y/%m/%d %H:%M") rescue "") row << t.join(";")
row << anns.place_translations["en"]
carousel_images = anns.event_carousel_images.asc(:created_at) row << anns.place_translations["zh_tw"]
t = carousel_images.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
t.delete(nil) row << (anns.event_end_date.strftime("%Y/%m/%d %H:%M") rescue "")
row << t.join(";")
t = carousel_images.collect{|l|l.description_translations["en"]} carousel_images = anns.event_carousel_images.asc(:created_at)
row << t.join(";") t = carousel_images.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
t = carousel_images.collect{|l|l.description_translations["zh_tw"]} t.delete(nil)
row << t.join(";") row << t.join(";")
sheet.add_row row t = carousel_images.collect{|l|l.description_translations["en"]}
end row << t.join(";")
t = carousel_images.collect{|l|l.description_translations["zh_tw"]}
row << t.join(";")
sheet.add_row row
end
end end