tag set presenter
This commit is contained in:
@@ -43,6 +43,10 @@ module PostSets
|
|||||||
tag_array.size == 1
|
tag_array.size == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_empty_tag?
|
||||||
|
tag_array.size == 0
|
||||||
|
end
|
||||||
|
|
||||||
def current_page
|
def current_page
|
||||||
[page.to_i, 1].max
|
[page.to_i, 1].max
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class RelatedTagCalculator
|
class RelatedTagCalculator
|
||||||
def self.find_tags(tag, limit)
|
def self.find_tags(tag, limit)
|
||||||
Post.tag_match(tag).limit(limit).select("posts.tag_string").order("posts.md5").map(&:tag_string)
|
Post.tag_match(tag).limit(limit).select("posts.tag_string").reorder("posts.md5").map(&:tag_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.calculate_from_sample_to_array(tags, category_constraint = nil)
|
def self.calculate_from_sample_to_array(tags, category_constraint = nil)
|
||||||
|
|||||||
@@ -661,7 +661,7 @@ class Post < ActiveRecord::Base
|
|||||||
relation = add_range_relation(q[:height], "posts.image_height", relation)
|
relation = add_range_relation(q[:height], "posts.image_height", relation)
|
||||||
relation = add_range_relation(q[:score], "posts.score", relation)
|
relation = add_range_relation(q[:score], "posts.score", relation)
|
||||||
relation = add_range_relation(q[:filesize], "posts.file_size", relation)
|
relation = add_range_relation(q[:filesize], "posts.file_size", relation)
|
||||||
relation = add_range_relation(q[:date], "posts.created_at::date", relation)
|
relation = add_range_relation(q[:date], "date(posts.created_at)", relation)
|
||||||
relation = add_range_relation(q[:general_tag_count], "posts.tag_count_general", relation)
|
relation = add_range_relation(q[:general_tag_count], "posts.tag_count_general", relation)
|
||||||
relation = add_range_relation(q[:artist_tag_count], "posts.tag_count_artist", relation)
|
relation = add_range_relation(q[:artist_tag_count], "posts.tag_count_artist", relation)
|
||||||
relation = add_range_relation(q[:copyright_tag_count], "posts.tag_count_copyright", relation)
|
relation = add_range_relation(q[:copyright_tag_count], "posts.tag_count_copyright", relation)
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
class PostSetPresenter < Presenter
|
|
||||||
attr_accessor :post_set, :tag_set_presenter
|
|
||||||
|
|
||||||
def initialize(post_set)
|
|
||||||
@post_set = post_set
|
|
||||||
@tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.calculate_from_sample_to_array(@post_set.tag_string).map {|x| x[0]})
|
|
||||||
end
|
|
||||||
|
|
||||||
def posts
|
|
||||||
post_set.posts
|
|
||||||
end
|
|
||||||
|
|
||||||
def tag_list_html(template)
|
|
||||||
tag_set_presenter.tag_list_html(template)
|
|
||||||
end
|
|
||||||
|
|
||||||
def post_previews_html(template)
|
|
||||||
html = "<div class='post-previews'>"
|
|
||||||
|
|
||||||
if posts.empty?
|
|
||||||
return template.render("post_sets/blank")
|
|
||||||
end
|
|
||||||
|
|
||||||
posts.each do |post|
|
|
||||||
html << PostPresenter.preview(post)
|
|
||||||
end
|
|
||||||
|
|
||||||
html << '</div>'
|
|
||||||
|
|
||||||
html.html_safe
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -10,14 +10,38 @@ module PostSetPresenters
|
|||||||
|
|
||||||
def related_tags
|
def related_tags
|
||||||
if post_set.is_single_tag?
|
if post_set.is_single_tag?
|
||||||
tag = Tag.find_by_name(post_set.tag_string)
|
related_tags_for_single
|
||||||
if tag
|
elsif post_set.is_empty_tag?
|
||||||
return tag.related_tag_array.map(&:first)
|
popular_tags
|
||||||
end
|
else
|
||||||
|
related_tags_for_group
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def popular_tags
|
||||||
|
n = 1
|
||||||
|
results = []
|
||||||
|
|
||||||
|
while results.empty? && n < 256
|
||||||
|
query = n.days.ago.strftime("date:>%Y-%m-%d")
|
||||||
|
results = RelatedTagCalculator.calculate_from_sample_to_array(query).map(&:first)
|
||||||
|
n *= 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
results
|
||||||
|
end
|
||||||
|
|
||||||
|
def related_tags_for_group
|
||||||
RelatedTagCalculator.calculate_from_sample_to_array(post_set.tag_string).map(&:first)
|
RelatedTagCalculator.calculate_from_sample_to_array(post_set.tag_string).map(&:first)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def related_tags_for_single
|
||||||
|
tag = Tag.find_by_name(post_set.tag_string)
|
||||||
|
|
||||||
|
if tag
|
||||||
|
return tag.related_tag_array.map(&:first)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def tag_list_html(template)
|
def tag_list_html(template)
|
||||||
tag_set_presenter.tag_list_html(template)
|
tag_set_presenter.tag_list_html(template)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class TagSetPresenter < Presenter
|
|||||||
def tag_list_html(template, options = {})
|
def tag_list_html(template, options = {})
|
||||||
html = ""
|
html = ""
|
||||||
html << "<ul>"
|
html << "<ul>"
|
||||||
@tags.flatten.each do |tag|
|
@tags.each do |tag|
|
||||||
html << build_list_item(tag, template, options)
|
html << build_list_item(tag, template, options)
|
||||||
end
|
end
|
||||||
html << "</ul>"
|
html << "</ul>"
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class CreatePosts < ActiveRecord::Migration
|
|||||||
add_index :posts, :uploader_id
|
add_index :posts, :uploader_id
|
||||||
add_index :posts, :uploader_ip_addr
|
add_index :posts, :uploader_ip_addr
|
||||||
|
|
||||||
|
execute "create index index_posts_on_created_at_date on posts (date(created_at))"
|
||||||
execute "CREATE INDEX index_posts_on_mpixels ON posts (((image_width * image_height)::numeric / 1000000.0))"
|
execute "CREATE INDEX index_posts_on_mpixels ON posts (((image_width * image_height)::numeric / 1000000.0))"
|
||||||
|
|
||||||
execute "SET statement_timeout = 0"
|
execute "SET statement_timeout = 0"
|
||||||
|
|||||||
@@ -3049,7 +3049,7 @@ create index index_posts_on_uploader_ip_addr on posts (uploader_ip_addr);
|
|||||||
drop function trg_posts_tags__delete();
|
drop function trg_posts_tags__delete();
|
||||||
drop function trg_posts_tags__insert();
|
drop function trg_posts_tags__insert();
|
||||||
update posts set uploader_id = 1 where uploader_id is null;
|
update posts set uploader_id = 1 where uploader_id is null;
|
||||||
|
create index index_posts_on_created_at_date on posts (date(created_at));
|
||||||
alter table post_appeals rename column user_id to creator_id;
|
alter table post_appeals rename column user_id to creator_id;
|
||||||
alter index index_post_appeals_on_user_id rename to index_post_appeals_on_creator_id;
|
alter index index_post_appeals_on_user_id rename to index_post_appeals_on_creator_id;
|
||||||
alter table post_appeals rename column ip_addr to creator_ip_addr;
|
alter table post_appeals rename column ip_addr to creator_ip_addr;
|
||||||
|
|||||||
Reference in New Issue
Block a user