Permalink
Browse files

topics#show 增加 etag 功能;

  • Loading branch information...
1 parent 1cb9d83 commit bd076fd9e6c06454fa5e6f5d05d586f81988ea5c @huacnlee huacnlee committed Dec 14, 2012
Showing with 22 additions and 4 deletions.
  1. +15 −0 app/controllers/application_controller.rb
  2. +7 −4 app/controllers/topics_controller.rb
@@ -83,4 +83,19 @@ def unread_notify_count
return 0 if current_user.blank?
@unread_notify_count ||= current_user.notifications.unread.count
end
+
+ def fresh_when(opts = {})
+ opts[:etag] ||= []
+ # 保证 etag 参数是 Array 类型
+ opts[:etag] = [opts[:etag]] if !opts[:etag].is_a?(Array)
+ # 加入页面上直接调用的信息用于组合 etag
+ opts[:etag] << current_user
+ opts[:etag] << Setting.app_name
+ opts[:etag] << SiteConfig.custom_head_html
+ opts[:etag] << SiteConfig.footer_html
+ opts[:etag] << SiteConfig.faye_server
+ opts[:etag] << Setting.google_analytics_key
+ opts[:etag] << unread_notify_count
+ super(opts)
+ end
end
@@ -11,7 +11,7 @@ def index
@topics = Topic.last_actived.without_hide_nodes.fields_for_list.includes(:user).paginate(:page => params[:page], :per_page => 15, :total_entries => 1500)
set_seo_meta("","#{Setting.app_name}#{t("menu.topics")}")
drop_breadcrumb(t("topics.topic_list.hot_topic"))
- #render :stream => true
+
end
def feed
@@ -25,7 +25,7 @@ def node
@topics = @node.topics.last_actived.fields_for_list.includes(:user).paginate(:page => params[:page],:per_page => 15)
set_seo_meta("#{@node.name} &raquo; #{t("menu.topics")}","#{Setting.app_name}#{t("menu.topics")}#{@node.name}",@node.summary)
drop_breadcrumb("#{@node.name}")
- render :action => "index" #, :stream => true
+ render :action => "index"
end
def node_feed
@@ -40,15 +40,15 @@ def node_feed
@topics = Topic.send(name.to_sym).last_actived.fields_for_list.includes(:user).paginate(:page => params[:page], :per_page => 15, :total_entries => 1500)
drop_breadcrumb(t("topics.topic_list.#{name}"))
set_seo_meta([t("topics.topic_list.#{name}"),t("menu.topics")].join(" &raquo; "))
- render :action => "index" #, :stream => true
+ render :action => "index"
end
end
def recent
@topics = Topic.recent.fields_for_list.includes(:user).paginate(:page => params[:page], :per_page => 15, :total_entries => 1500)
drop_breadcrumb(t("topics.topic_list.recent"))
set_seo_meta([t("topics.topic_list.recent"),t("menu.topics")].join(" &raquo; "))
- render :action => "index" #, :stream => true
+ render :action => "index"
end
def show
@@ -72,6 +72,9 @@ def show
set_seo_meta("#{@topic.title} &raquo; #{t("menu.topics")}")
drop_breadcrumb("#{@node.try(:name)}", node_topics_path(@node.try(:id)))
drop_breadcrumb t("topics.read_topic")
+
+ fresh_when(:etag => [@topic,@replies,@node])
+ expires_in 1.days
end
def new

0 comments on commit bd076fd

Please sign in to comment.