Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug fix.

  • Loading branch information...
commit 7bd2f18bb1af09c5af871dbc6dc858e0fefae2b9 1 parent e06f1be
@huacnlee authored
View
11 app/controllers/posts_controller.rb
@@ -51,20 +51,15 @@ def rss
end
def show
- # update pv
-
+ # update pv
@view_count = Post.update_view_count(params[:id])
- @post = Post.find_slug(params[:id])
+ @post = Post.publish.where(:slug => params[:id]).includes(:category).first
if not @post
return render_404
end
- set_seo_meta(@post.title,@post.meta_keywords,@post.meta_description)
-
-
+ set_seo_meta(@post.title,@post.meta_keywords,@post.meta_description)
end
-
-
end
View
16 app/models/post.rb
@@ -45,20 +45,6 @@ def delay_view_count
Rails.cache.read(cache_key).to_i || 0
end
- # custom method
- public
- # show
- def self.find_slug(slug)
- p = Rails.cache.read("models/posts/#{slug}")
- if not p
- p = find_by_slug_and_status(slug,1)
- Rails.cache.write("models/posts/#{slug}",p)
- end
- return p
- end
-
-
- # static method
def self.update_view_count(slug)
delay = 10
cache_key = "data/posts/view_count/#{slug}"
@@ -67,7 +53,7 @@ def self.update_view_count(slug)
post = find_by_slug(slug)
if post
post.view_count += count + 1
- post.save
+ Post.where(:id => post.id).update_all(:view_count => post.view_count)
end
count = 0
else
View
9 app/models/tweet.rb
@@ -8,8 +8,13 @@ def self.gets(uid = 'huacnlee',count = 5,force = false)
key = "data/tweet/#{uid}/#{count}"
msgs = Rails.cache.read(key)
if not msgs or force
- msgs = Twitter.user_timeline(uid, :count => count, :include_rts => true)
- Rails.cache.write(key,msgs, :expires_in => 15.minutes)
+ begin
+ msgs = Twitter.user_timeline(uid, :count => count, :include_rts => true)
+ Rails.cache.write(key,msgs, :expires_in => 15.minutes)
+ rescue => e
+ Rails.logger.error("Tweet.gets failed: #{e}")
+ msgs = []
+ end
end
msgs
end
View
2  app/sweepers/post_sweeper.rb
@@ -17,7 +17,7 @@ def after_destroy(post)
def sweeper(post)
clear_index_recent_posts
- expire_action "/blog/rss"
+ # expire_action "/blog/rss"
Rails.cache.delete("models/posts/#{post.slug}")
Rails.cache.delete("data/categories")
Rails.cache.touch_tag("posts_list")
View
8 app/views/posts/_tags.html.erb
@@ -0,0 +1,8 @@
+<% cache("posts/#{post.id}:#{post.updated_at.to_i}/tags") do %>
+ <% if not post.tags.blank? %>
+ <label style="margin-left:20px;">Tags:</label>
+ <% for tag in post.tags %>
+ <a href="<%= blogs_path(:tag => tag.name) %>"><%= tag.name %></a>
+ <% end %>
+ <% end %>
+<% end %>
View
9 app/views/posts/show.html.erb
@@ -1,7 +1,7 @@
<div id="content">
<div class="entry">
<h1>
- <a href="<%= blog_path(@post.slug) %>" rel="nofollow"><%= h(@post.title) %></a>
+ <a href="<%= blog_path(@post.slug) %>" rel="nofollow"><%= @post.title %></a>
</h1>
<div class="date">
<%= link_to (@post.category.name), category_blogs_path(@post.category.slug) %>
@@ -13,12 +13,7 @@
<div class="footer">
<span class="view_count"><%= @post.view_count + @view_count %> Views</span>,
<span class="comment_count"><a href="#disqus_thread" ata-disqus-identifier="disqus:huacnlee:posts:<%= @post.id %>">Comments</a></span>
- <% if !@post.tags.blank? %>
- <label style="margin-left:20px;">Tags:</label>
- <% for tag in @post.tags %>
- <a href="<%= blogs_path(:tag => tag.name) %>" class="rbox"><%= tag.name %></a>
- <% end %>
- <% end %>
+ <%= render "tags", :post => @post %>
</div>
</div>
<div id="disqus_thread"></div>
Please sign in to comment.
Something went wrong with that request. Please try again.