From 929408a421a26af1e452f25f6587f8d07898e124 Mon Sep 17 00:00:00 2001 From: Toks Date: Wed, 8 Jan 2014 14:40:07 -0500 Subject: [PATCH] fixes #2066 --- app/helpers/tags_helper.rb | 5 +++++ app/models/tag.rb | 6 ++++++ app/views/tags/index.html.erb | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 23450bc5c..788e02747 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -1,2 +1,7 @@ module TagsHelper + def tag_post_count_style(tag) + @highest_post_count ||= Tag.highest_post_count + width_percent = Math.log(tag.post_count, @highest_post_count) * 100 + "background: linear-gradient(to left, #DDD #{width_percent}%, white #{width_percent}%)" + end end diff --git a/app/models/tag.rb b/app/models/tag.rb index b0a89e21f..bc7203f98 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -41,6 +41,12 @@ class Tag < ActiveRecord::Base def counts_for(tag_names) select_all_sql("SELECT name, post_count FROM tags WHERE name IN (?)", tag_names) end + + def highest_post_count + Cache.get("highest-post-count", 4.hours) do + select("post_count").order("post_count DESC").first.post_count + end + end end def real_post_count diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 6c5b83a8e..603f379c1 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -12,7 +12,7 @@ <% @tags.each do |tag| %> - <%= tag.post_count %> + <%= tag.post_count %> <%= link_to("?", show_or_new_wiki_pages_path(:title => tag.name)) %> <%= link_to(tag.name, posts_path(:tags => tag.name)) %>