announcement-test/temp_file/config/environment.rb

108 lines
3.5 KiB
Ruby
Raw Normal View History

# Load the Rails application.
require File.expand_path('../application', __FILE__)
require File.expand_path('../../app/helpers/orbit_helper', __FILE__)
OrbitHelper.const_set("SharedMutex",Thread.current[:shared_mutex])
OrbitHelper.const_set("SharedHash",Thread.current[:shared_hash])
# Initialize the Rails application.
Orbit::Application.initialize!
Orbit::Application.config.secret_key_base = 'acc6ffc5a7d360c9cf2a7bdb4ddf9a897942ec6767413a5c0324a0fa8b86197a96298288a66bd46d8770d8b6edf509aad65716961c2c364ce006b475e6cfd418'
site = Site.first
default_locale = (site.default_locale rescue I18n.available_locales[0]) rescue nil
if !default_locale.nil?
I18n.default_locale = default_locale
I18n.locale = default_locale
end
2024-02-24 06:54:42 +00:00
[MemberProfile,Role,RoleStatus,AttributeValue,AttributeField,MemberProfileField,MemberProfileFieldValue,MemberProfileDefaultField,MemberRelation].each do |m|
m.class_eval{include MemberCleanCache}
end
require File.expand_path('../../app/models/page_cache_model', __FILE__) rescue nil
if (site.enable_cache rescue false)
module MongoidObs
require 'active_support/concern'
extend ActiveSupport::Concern
included do
2024-02-24 06:54:42 +00:00
excluded_classes = [Asset,AssetTag,Email,EmailFile,EmailLog,Multithread,Site,Impression,ModuleApp,OrbitMemberModule,OrbitWidget,PageCacheModel,UserAction,UserLoginLog,TicketStatus,Workgroup,MemberIndexCache,MemberEditTemp]
excluded_classes += OrbitApp::Module::Registration.avoid_page_cache
if excluded_classes.exclude?(self)
custom_flag = false
if self == Page
def delete_page_cache
if self.changed? || self.new_record?
drop_flag = false
if self.changed != ['view_count']
if (['access_level', 'always_show_on_menu'] & self.changed).count != 0
drop_flag = true
end
end
if drop_flag
PageCacheModel.delete_all
else
2024-02-24 06:54:42 +00:00
caches = PageCacheModel.where(page_id: self.id).only(:page_id)
PageCacheModel.delete_roda_caches(caches)
caches.delete
end
end
true #return true to save ok
end
2024-02-24 06:54:42 +00:00
elsif [SubPart, PagePart].include?(self)
def delete_page_cache
if self.changed? || self.new_record?
page = self.page rescue nil
if page
2024-02-24 06:54:42 +00:00
caches = PageCacheModel.where(page_id: self.id).only(:page_id)
PageCacheModel.delete_roda_caches(caches)
caches.delete
end
end
true #return true to save ok
end
elsif self.instance_methods.include?(:delete_page_cache_custom)
custom_flag = true
else
def delete_page_cache
if self.changed? || self.new_record?
PageCacheModel.delete_all
end
true #return true to save ok
end
end
if custom_flag
self.after_save :delete_page_cache_custom
2024-02-24 06:54:42 +00:00
self.before_destroy :delete_page_cache_custom
else
self.after_save :delete_page_cache
2024-02-24 06:54:42 +00:00
self.before_destroy :delete_page_cache
end
end
end
end
module MongoidObsWrap
def included(m)
super(m)
m.include(MongoidObs)
end
end
Mongoid::Document.extend(MongoidObsWrap)
preload_models = Mongoid.models
preload_models.each{|v| v.include(MongoidObs)}
end
if Rails.env != "production"
load_models = %w(app/models/attribute_value.rb app/models/member_profile_field_value.rb)
load_models.each do |load_model|
load(load_model)
end
end
$Orbit_Categorized = JSON.parse(File.read("orbit_categorized_tmp.txt")) rescue {}
if ENV['worker_num'] == '0'
if defined?(PageCacheModel)
PageCacheModel.collection.drop
PageCacheModel.create_indexes
end
require File.expand_path('../do_on_startup', __FILE__)
end