1. accelerate feed and search

2. fix feed error
This commit is contained in:
邱博亞 2024-10-13 21:46:48 +08:00
parent caa6fb56c5
commit b59593aa39
11 changed files with 250 additions and 215 deletions

View File

@ -585,6 +585,12 @@ class Admin::EventNewsController < OrbitAdminController
def update_is_postdate_sort_first(setting)
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first] = setting.is_postdate_sort_first
feeds_time_field = (EventNewsHelper.is_postdate_sort_first ? ['postdate', 'event_date'] : ['event_date', 'postdate'])
@module_app.feeds_time_field = feeds_time_field
@module_app.save
if defined?(Feeds)
Feeds::Migrate.sync_module_apps
end
end
end
end

View File

@ -51,9 +51,9 @@ class EventNewsFeedsController < ApplicationController
if !@bf.nil?
tags = @bf.tag_ids
if !tags.empty?
@event_news = EventNews.can_display_and_sorted.is_approved.filter_by_tags(tags)
@event_news = EventNews.can_display_and_sorted.filter_by_tags(tags)
else
@event_news = EventNews.can_display_and_sorted.is_approved
@event_news = EventNews.can_display_and_sorted
end
categories = @bf.category_ids
if !categories.empty?

View File

@ -24,8 +24,8 @@ class EventNewsModsController < ApplicationController
desc = (desc.blank? ? "EventNews image" : desc)
link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)
target = a.is_external_link ? "_blank" : "_self"
doc = Nokogiri::HTML(a.title)
title = doc.text.empty? ? 'no content' : doc.text
title = a.title_plain_text
title = 'no content' if title.blank?
event_time = a.event_time_formated_for_frontend
event_time_formated = a.event_time_formated
{
@ -142,6 +142,8 @@ class EventNewsModsController < ApplicationController
get_tabs_option
event_news = []
use_tag = false
tags = tags.collect{|tag| tag.to_s}
cats = cats.collect{|cat| cat.to_s}
if @tab_option == 0
event_news = get_event_news_for_pack_data(cats,tags,nil,is_random)
else
@ -164,26 +166,18 @@ class EventNewsModsController < ApplicationController
else
cats = ["all"] + cats
end
event_news = event_news.sort_by { |a| tmp=a["event_date"].blank?;[tmp ? 0 : 1, tmp ? nil : a["event_date"].to_time] }.reverse
event_news = sort_event_news(event_news)
end
cats = cats.uniq
tags = tags.uniq
tags_translations = tags.map{|tag_id|
if tag_id == "all"
t = I18n.t(:all)
else
t = Tag.find(tag_id).name rescue ""
end
[tag_id,t]
}.to_h
cats_translations = cats.map{|cat_id|
if cat_id == "all"
t = I18n.t(:all)
else
t = Category.find(cat_id).title rescue ""
end
[cat_id,t]
}.to_h
tags_translations = {'all' => I18n.t(:all)}
Tag.where(:id.in => tags).pluck(:id, :title).each{|id, title_translations|
tags_translations[id.to_s] = title_translations[I18n.locale]
}
cats_translations = {'all' => I18n.t(:all)}
Category.where(:id.in => cats).pluck(:id, :title).each{|id, title_translations|
cats_translations[id.to_s] = title_translations[I18n.locale]
}
cats_relations = cats_translations.map{|cat_id,t|
if cat_id == "all"
t = "all"
@ -420,9 +414,11 @@ class EventNewsModsController < ApplicationController
@all_setting_option = 0
@image_version = 'thumb'
@show_today_data_first = false
@show_options = nil
if subpart.methods.include? 'select_options'.to_sym
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news_mod'}.each do |modile_app|
@show_options = modile_app.show_options rescue nil
module_app = ModuleApp.where(key: 'event_news_mod').first
if module_app
@show_options = module_app.show_options
end
subpart.select_options.each do |select_option|
if !(@show_options.nil?)
@ -528,15 +524,15 @@ class EventNewsModsController < ApplicationController
event_news = event_news_cache.first.filter_result
end
if devide_flag
feeds_event_news = get_feed_event_news("widget",nil,cats,widget_data_count - top_event_news.count)
top_event_news = top_event_news + feeds_event_news.select{|v| v['is_top'] == true}
top_event_news = top_event_news.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse
feeds_event_news, _ = get_feed_event_news("widget",nil,cats,widget_data_count - top_event_news.count)
top_event_news += feeds_event_news.select{|v| v['is_top'] == true}
top_event_news = sort_event_news(top_event_news)
rest_count = widget_data_count - top_event_news.count
if rest_count <= 0
event_news = top_event_news.take(widget_data_count)
else
rest_all_event_news = feeds_event_news.select{|v| v['is_top'] != true} + not_top_event_news.take(rest_count)
rest_event_news = rest_all_event_news.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse.take(rest_count)
rest_event_news = sort_event_news(rest_all_event_news).take(rest_count)
event_news = top_event_news + rest_event_news
end
end
@ -835,8 +831,8 @@ class EventNewsModsController < ApplicationController
desc = (desc.blank? ? "EventNews image" : desc)
link_to_show = (a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)) rescue ""
target = a.is_external_link ? "_blank" : "_self"
doc = Nokogiri::HTML(a.title)
title = doc.text.empty? ? 'no content' : doc.text
title = a.title_plain_text
title = 'no content' if title.blank?
event_time = a.event_time_formated_for_frontend
event_time_formated = a.event_time_formated
{

View File

@ -1,25 +1,4 @@
module EventNewsHelper
def self.complementaryColor(my_hex)
if my_hex[0] == '#'
my_hex = my_hex[1..-1]
end
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')}
'#'+comp.join
end
def self.lighten_color(my_hex,percent)
if my_hex[0] == '#'
my_hex = my_hex[1..-1]
end
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
comp = rgb.collect do |a|
tmp = a.to_i(16)*(1+percent/100.0)
tmp = 255 if tmp>255
tmp = 0 if tmp < 0
tmp.to_i.to_s(16).rjust(2,'0')
end
'#'+comp.join
end
def data_to_human_type(a,set_tag_ids=nil)
statuses = a.statuses_with_classname.collect do |status|
{
@ -75,7 +54,7 @@ module EventNewsHelper
"img_description" => desc
}
end
def get_feed_annc(type,site_source,locale,categories=nil,max_len=nil)
def get_feed_annc(type,site_source,locale,categories=nil,max_len=nil,sort_maps=nil,extra_match_cond=nil)
ma_key = 'event_news_mod'
if categories.nil?
if type == "index"
@ -87,116 +66,58 @@ module EventNewsHelper
end
end
categories = ["all"] if categories.length==0
data = SiteFeedAnnc.get_feed_cache(ma_key,categories,site_source,locale,type=='widget',max_len)
data = SiteFeedAnnc.get_feed_cache(
ma_key,
categories,
site_source,
locale,
type=='widget',
max_len,
sort_maps,
extra_match_cond
)
data
end
def get_feed_event_news(type,site_source=nil,categories=nil,max_len=nil)
def get_feed_event_news(type,site_source=nil,categories=nil,max_len=nil,extra_match_cond=[])
locale = OrbitHelper.get_site_locale.to_s
feeds = []
feeds_count = 0
if !(defined? SiteFeedAnnc).nil?
fans = get_feed_annc(type,site_source,locale,categories,max_len)
sort_maps = nil
if @show_today_data_first
sort_maps = {event_date: :asc, is_top: :desc, postdate: :asc, id: :asc}
else
feed_anns = OrbitHelper.get_feed_for_module(type)
fans = []
feed_anns.each do |fa|
next if !site_source.nil? && site_source != fa["source-site-title"]
status = {
"status" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
"status-class" => "status-source"
sort_maps = {is_top: :desc}
if EventNewsHelper.is_postdate_sort_first
sort_maps = sort_maps.merge({postdate: :desc, event_date: :desc, id: :desc})
else
sort_maps = sort_maps.merge({event_date: :desc, postdate: :desc, id: :desc})
end
end
match_cond = {
"is_hidden" => {"$ne" => true},
"$and" => [
{"postdate" => {"$lte"=> Time.now}},
{
"$or" => [
{"deadline" => {"$gte"=> Time.now}},
{"deadline" => nil}
]
}
],
"title" => {"$gt"=>""}
}
if !extra_match_cond.empty?
match_cond["$and"] += extra_match_cond
end
if @show_today_data_first
match_cond["event_date"] = {"$gte" => Date.today.to_time}
end
feeds, feeds_count = get_feed_annc(type,site_source,locale,categories,max_len,sort_maps,match_cond)
end
return feeds, feeds_count
end
files = fa["event_news_files"].collect{|bf| { "file_url" => bf["file_url"], "file_title" => fa["file_title_translations"][locale] }} rescue []
links = fa["event_news_links"].map{|link| { "link_url" => link["link_url"], "link_title" => link["link_title_translations"][locale] } } rescue []
event_time_formated = a.event_time_formated
s = DateTime.parse(fa["event_date"]) rescue nil
e = DateTime.parse(fa["event_end_date"]) rescue nil
date_parse_format = fa["all_day"] ? '%Y-%m-%d' : '%Y-%m-%d %H:%M'
if s.blank? && e.blank?
event_time_formated = ""
elsif s.blank?
event_time_formated = s.strftime(date_parse_format)
elsif e.blank?
event_time_formated = "~ " + e.strftime(date_parse_format)
else
if s.to_date == e.to_date
date_str = s.strftime('%Y-%m-%d')
s_time = s.strftime('%H:%M')
e_time = e.strftime('%H:%M')
event_time_formated = "#{date_str} #{s_time} ~ #{e_time}"
else
event_time_formated = s.strftime(date_parse_format) + " ~ " + e.strftime(date_parse_format)
end
end
x = {
"event_news_links" => links,
"event_news_files" => files,
"event_carousel_images" => fa["event_carousel_images"].to_a,
"title" => fa["title_translations"][locale],
"speaker-css" => (fa["speaker_translations"][locale].blank? ? "display: none;" : ""),
"host-css" => (fa["host_translations"][locale].blank? ? "display: none;" : ""),
"place-css" => (fa["place_translations"][locale].blank? ? "display: none;" : ""),
"event-time-css" => (event_time_formated.blank? ? "display: none;" : ""),
"notes-css" => (fa["notes_translations"][locale].blank? ? "display: none;" : ""),
"event-time-formated" => event_time_formated,
"speaker" => (fa["speaker_translations"][locale].to_s rescue ""),
"place" => (fa["place_translations"][locale].to_s rescue ""),
"host" => (fa["host_translations"][locale].to_s rescue ""),
"notes" => (fa["notes_translations"][locale].to_s rescue ""),
"subtitle" => fa["subtitle_translations"][locale],
"statuses" => [status],
"category" => fa["category"],
"postdate" => (DateTime.parse(fa["event_date"]) rescue DateTime.now),
"event_date" => (DateTime.parse(fa["event_date"]) rescue DateTime.now),
"author" => fa["author"],
"source-site" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
"source-site-title" => fa["source-site-title"],
"source-site-link" => fa["source-site"],
"link_to_show" => OrbitHelper.url_to_show(fa["params"]),
"target" => "_self",
"img_src" => fa["image"]["thumb"] || "/assets/event_news-default.jpg",
"img_description" => fa["image_description_translations"][locale],
"more" => t("event_news.more"),
"view_count" => ""
}
if (!x["title"].empty? rescue false)
fans << x
end
end
end
fans
end
def filter_by_keywords(sorted,keywords,stime,etime)
kflag = keywords.blank?
sflag = stime.blank?
eflag = etime.blank?
stime = stime.to_s.split('/')
stime = Time.zone.local(*stime) rescue nil
etime = etime.to_s.split('/')
etime = Time.zone.local(*etime) rescue nil
if !kflag || !sflag || !eflag
sorted.select{|anns|
if kflag
flag = true
else
if anns["source-site"].present?
title = Nokogiri::HTML(anns["title"].to_s).text
else
title = Nokogiri::HTML(anns.title.to_s).text
end
flag = title.include?(keywords.to_s)
end
if sflag && !eflag
flag = flag && (anns.event_date<=etime)
elsif !sflag && eflag
flag = flag && (anns.event_date>=stime)
elsif !sflag && !eflag
flag = flag && (anns.event_date>=stime) && (anns.event_date<=etime)
end
flag
}
else
sorted
end
end
def get_sorted_event_news(data_count=nil)
params = OrbitHelper.params
locale = OrbitHelper.get_site_locale.to_s
@ -208,9 +129,7 @@ module EventNewsHelper
tags = @tags
categories = @categories
else
page = OrbitHelper.page rescue nil
page = Page.where(url:params['url']).first if page.nil?
page = OrbitHelper.page
tags = page.tags
tags = params[:tags] if params[:tags].present?
categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || []))
@ -241,6 +160,7 @@ module EventNewsHelper
end
end
if @enable_search_flag
if categories.include? 'all'
@categories = module_app.categories
else
@ -248,15 +168,39 @@ module EventNewsHelper
@categories = categories.map{|v| cat_maps[v.to_s]}.compact
end
end
end
event_news_list = []
event_news = []
feeds_count = 0
extra_match_cond = []
if !params[:keywords].blank?
extra_match_cond << {
"title_plain_text" => OrbitHelper.get_keyword_regex(params[:keywords])
}
end
if !params[:stime].blank?
stime = OrbitHelper.get_time_from_str(params[:stime])
extra_match_cond << {
"event_date" => {"$gte" => stime}
}
end
if !params[:etime].blank?
etime = OrbitHelper.get_time_from_str(params[:etime]) + 1.days
extra_match_cond << {
"event_date" => {"$lt" => etime}
}
end
if !extra_match_cond.empty?
event_news = event_news.and(extra_match_cond)
end
if !params["source"].present?
event_news = @show_today_data_first ?
EventNews.can_display_and_sorted_according_today :
EventNews.can_display_and_sorted
event_news = event_news
.where(:title.nin => ["",nil])
.filter_by_categories(categories, false).filter_by_tags(tags)
.where(:title.nin => ["",nil])
if @type == "show_widget"
if !params[:uids].blank?
member_profile = MemberProfile.any_in(:uid=>params[:uids])
@ -264,45 +208,45 @@ module EventNewsHelper
event_news = event_news.where(:create_user_id.in=>user_ids)
end
end
event_news = event_news.limit(page_number*page_data_count)
event_news_list = event_news.to_a
if !(defined? SiteFeed).nil?
if @type != "show_widget"
feeds_anns = get_feed_event_news("index",nil,nil,page_number*page_data_count)
else
feeds_anns = []
end
end
else
if @type != "show_widget"
feeds_anns = get_feed_event_news("index",params["source"],nil,page_number*page_data_count)
else
feeds_anns = []
if !(defined? SiteFeed).nil? && @type != "show_widget"
feeds_anns, feeds_count = get_feed_event_news("index",nil,nil,page_number*page_data_count, extra_match_cond)
end
elsif @type != "show_widget"
feeds_anns, feeds_count = get_feed_event_news("index",params["source"],nil,page_number*page_data_count, extra_match_cond)
end
if !feeds_anns.blank?
if event_news_list.count != 0
top_anns = event_news_list.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']}
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + event_news_list.select{|v| !v.is_top}
all_sorted = sort_event_news(top_anns) + sort_event_news(rest_all_anns)
rest_all_anns = event_news_list.select{|v| !v.is_top} + feeds_anns.select{|v| v['is_top'] != true}
all_filter = sort_event_news(top_anns) + sort_event_news(rest_all_anns)
else
all_sorted = sort_event_news(feeds_anns.select{|v| v['is_top']}) + sort_event_news(feeds_anns.select{|v| v['is_top'] != true})
end
all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime])
else
all_filter = filter_by_keywords(event_news_list,params[:keywords],params[:stime],params[:etime])
all_filter = event_news_list
end
if page_data_count != 0
sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count]
else
sorted = all_filter
end
annc_count = all_filter.count
annc_count = event_news.count + feeds_count
total_pages = page_data_count == 0 ? 1 : (annc_count.to_f / page_data_count).ceil
[sorted,total_pages]
end
def sort_event_news(event_news_list)
enable_manually_sort = enable_manually_sort
if @show_today_data_first || !EventNewsHelper.is_postdate_sort_first
if enable_manually_sort
event_news_list = event_news_list.sort_by { |event_news|
tmp1 = event_news["event_date"].blank?
tmp2 = event_news["postdate"].blank?
[
(@show_today_data_first ? a['sort_number'].to_i : -a['sort_number'].to_i),
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time,
tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time
]
}
else
event_news_list = event_news_list.sort_by { |event_news|
tmp1 = event_news["event_date"].blank?
tmp2 = event_news["postdate"].blank?
@ -311,9 +255,21 @@ module EventNewsHelper
tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time
]
}
end
if !@show_today_data_first
event_news_list = event_news_list.reverse
end
else
if enable_manually_sort
event_news_list = event_news_list.sort_by { |event_news|
tmp1 = event_news["event_date"].blank?
tmp2 = event_news["postdate"].blank?
[
-a['sort_number'].to_i,
tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time,
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time
]
}.reverse
else
event_news_list = event_news_list.sort_by { |event_news|
tmp1 = event_news["event_date"].blank?
@ -324,6 +280,7 @@ module EventNewsHelper
]
}.reverse
end
end
return event_news_list
end
@ -594,14 +551,36 @@ module EventNewsHelper
</div>
</div>").html_safe
end
def self.enable_manually_sort
class << self
def complementaryColor(my_hex)
if my_hex[0] == '#'
my_hex = my_hex[1..-1]
end
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')}
'#'+comp.join
end
def lighten_color(my_hex,percent)
if my_hex[0] == '#'
my_hex = my_hex[1..-1]
end
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
comp = rgb.collect do |a|
tmp = a.to_i(16)*(1+percent/100.0)
tmp = 255 if tmp>255
tmp = 0 if tmp < 0
tmp.to_i.to_s(16).rjust(2,'0')
end
'#'+comp.join
end
def enable_manually_sort
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort]
else
EventNewsSetting.first.enable_manually_sort rescue false
end
end
def self.is_postdate_sort_first
def is_postdate_sort_first
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first]
else
@ -609,3 +588,4 @@ module EventNewsHelper
end
end
end
end

View File

@ -8,8 +8,8 @@ class EventNews
include OrbitTag::Taggable
include OrbitCategory::Categorizable
include Slug
require 'event_news_model/cache'
include EventNewsModel::Cache
require 'event_news_mod/cache'
include EventNewsMod::Cache
attr_accessor :org_tag_ids, :org_category_id
def tags=(ids)
self.org_tag_ids = self.tag_ids
@ -39,8 +39,8 @@ class EventNews
end
super(index,value)
end
SubPart.class_eval { include EventNewsModel::Cache }
Page.class_eval { include EventNewsModel::Cache }
SubPart.class_eval { include EventNewsMod::Cache }
Page.class_eval { include EventNewsMod::Cache }
before_destroy do
EventNewsCache.all.destroy
end
@ -63,6 +63,7 @@ class EventNews
field :event_id
field :place, type: String, localize: true
field :title, as: :slug_title, type: String, localize: true
field :title_plain_text, type: String, localize: true
field :speaker, type: String, localize: true
field :host, type: String, localize: true
field :subtitle, localize: true
@ -142,6 +143,7 @@ class EventNews
if self.is_top_changed? && !self.is_top
self.sort_number = nil
end
self.migrate_title_plain_text
end
index({postdate: 1}, { unique: false, background: true })
index({is_top: -1, postdate: -1, event_date: -1, _id: -1}, { unique: false, background: true })
@ -466,7 +468,7 @@ class EventNews
a["notes_translations"] = self.notes_translations
a["text_translations"] = {}
text_translations = self.text_translations
self.text_translations.each do |l, text|
text_translations.each do |l, text|
a["text_translations"][l] = self.class.smart_convertor(text,base_url)
end
a["event_date"] = self.event_date
@ -503,7 +505,7 @@ class EventNews
self.event_news_links.each do |bl|
b = {}
b["link_url"] = bl.url
b["link_title_translations"] = bl.title_translations.map{|k,v| [k, (v.blank? ? b["url"] : v)]}.to_h
b["link_title_translations"] = bl.title_translations.map{|k,v| [k, (v.blank? ? b["link_url"] : v)]}.to_h
a["event_news_links"] << b
end
self.event_news_files.each do |bf|
@ -511,7 +513,7 @@ class EventNews
b = {}
b["description_translations"] = bf.description_translations
b["file_url"] = base_url + bf.file.url
b["file_title_translations"] = bf.title_translations.map{|k,v| [k, (v.blank? ? File.basename(b["url"]) : v)]}.to_h
b["file_title_translations"] = bf.title_translations.map{|k,v| [k, (v.blank? ? File.basename(b["file_url"]) : v)]}.to_h
a["event_news_files"] << b
end
return a
@ -558,6 +560,11 @@ class EventNews
end
end
end
def migrate_title_plain_text
self.title_plain_text_translations = OrbitHelper.get_plain_text_translations(self.title_translations)
end
def self.notify_all_feed(force_update=false)
related_feeds = EventNewsFeed.where(:remote_urls.nin=>[nil, []]).to_a
related_feeds.each do |feed|

View File

@ -13,6 +13,9 @@ class EventNewsSetting
field :hour_clock_24, type: Boolean, default: true
field :enable_manually_sort, type: Boolean, default: false
field :is_postdate_sort_first, type: Boolean, default: false
field :migrate_flag, type: Array, default: []
has_many :event_news_status_settings, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :event_news_status_settings, :allow_destroy => true

View File

@ -1,9 +1,4 @@
Rails.application.routes.draw do
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
Thread.new do
EventNewsFeedCache.regenerate_all
end
end
locales = Site.first.in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do

View File

@ -1,4 +1,6 @@
require "event_news_mod/engine"
require "event_news_mod/cache"
require "event_news_mod/migrate"
module EventNewsMod
end

View File

@ -1,4 +1,4 @@
module EventNewsModel
module EventNewsMod
module Cache
require 'active_support/concern'
extend ActiveSupport::Concern

View File

@ -92,6 +92,17 @@ module EventNewsMod
rescue => e
puts ['error in event_news',e,e.backtrace]
end
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
Thread.new do
begin
Migrate.call
rescue => e
puts ['event_news_mod',e, e.backtrace]
end
end
end
OrbitApp.registration "event_news_mod", :type => "ModuleApp" do
db = ::Mongoid::Sessions.default
collection = db[:module_apps]
@ -117,6 +128,7 @@ module EventNewsMod
authorizable
frontend_enabled
feeds_url "/xhr/event_news/feeds"
feeds_time_field (EventNewsHelper.is_postdate_sort_first ? ['postdate', 'event_date'] : ['event_date', 'postdate'])
data_count 1..30
begin
show_options data

View File

@ -0,0 +1,34 @@
module EventNewsMod
module Migrate
def self.call
puts ['event news migrate start']
gem_root = EventNewsMod::Engine.root
require File.join(gem_root, 'app/models/event_news_setting')
require File.join(gem_root, 'app/models/event_news')
require File.join(gem_root, 'app/models/event_news_feed')
require File.join(gem_root, 'app/models/event_news_feed_cache')
setting = EventNewsSetting.first
if !setting.migrate_flag.include?("v1")
EventNews.all.pluck(:id, :title).each do |id, title_translations|
if title_translations.nil?
next
end
EventNews.where(id: id).view.update_many({
"$set" => {
title_plain_text: OrbitHelper.get_plain_text_translations(title_translations)
}
})
end
setting.migrate_flag << "v1"
setting.save
end
EventNewsFeedCache.regenerate_all
puts ['event news migrate end']
end
end
end