diff --git a/Rakefile b/Rakefile index 5458f365..97f119ff 100644 --- a/Rakefile +++ b/Rakefile @@ -140,11 +140,11 @@ task :cleantags => [:environment] do Tag.all.each do |tag| if tag.name.length > Tag::NAME_LENGTH_MAX - tag.sites.each { |site| tag.remove_site site } + tag.sites.each { |site| site.remove_tag tag } tag.delete + else + tag.update name: tag.name.downcase.strip end - - tag.update name: tag.name.downcase.strip end Tag.all.each do |tag| @@ -161,9 +161,11 @@ task :cleantags => [:environment] do matching_tag.delete end end + + Tag.where(name: 'porn').first.update is_nsfw: true end - require 'thread/pool' +require 'thread/pool' desc 'update screenshots' task :update_screenshots => [:environment] do diff --git a/app.rb b/app.rb index dc142b99..59c2ea56 100644 --- a/app.rb +++ b/app.rb @@ -429,11 +429,12 @@ get '/browse/?' do end end - site_dataset.filter! is_nsfw: (params[:is_nsfw] == 'true' ? true : false) + site_dataset.where! ['sites.is_nsfw = ?', (params[:is_nsfw] == 'true' ? true : false)] if params[:tag] site_dataset = site_dataset.association_join(:tags) site_dataset.where! ['tags.name = ?', params[:tag]] + site_dataset.where! ['tags.is_nsfw = ?', (params[:is_nsfw] == 'true' ? true : false)] end site_dataset = site_dataset.paginate @current_page, 300 diff --git a/models/tag.rb b/models/tag.rb index d06e9190..2ec4cce4 100644 --- a/models/tag.rb +++ b/models/tag.rb @@ -19,10 +19,10 @@ class Tag < Sequel::Model end def self.autocomplete(name, limit=3) - DB["select tags.name,count(*) as c from sites_tags inner join tags on tags.id=sites_tags.tag_id inner join sites on sites.id=sites_tags.site_id where is_deleted='f' and is_banned='f' and is_crashing='f' and site_changed='t' and tags.name != '' and tags.name LIKE ? group by tags.name having count(*) > 1 order by c desc LIMIT ?", name+'%', limit].all + DB["select tags.name,count(*) as c from sites_tags inner join tags on tags.id=sites_tags.tag_id inner join sites on sites.id=sites_tags.site_id where is_deleted='f' and is_banned='f' and is_crashing='f' and site_changed='t' and tags.is_nsfw='f' and tags.name != '' and tags.name LIKE ? group by tags.name having count(*) > 1 order by c desc LIMIT ?", name+'%', limit].all end def self.popular_names(limit=10) - DB["select tags.name,count(*) as c from sites_tags inner join tags on tags.id=sites_tags.tag_id where tags.name != '' group by tags.name having count(*) > 1 order by c desc LIMIT ?", limit].all + DB["select tags.name,count(*) as c from sites_tags inner join tags on tags.id=sites_tags.tag_id where tags.name != '' and tags.is_nsfw='f' group by tags.name having count(*) > 1 order by c desc LIMIT ?", limit].all end end