diff --git a/app/admin.rb b/app/admin.rb index 09201000..7b2ce889 100644 --- a/app/admin.rb +++ b/app/admin.rb @@ -301,5 +301,9 @@ get '/admin/masquerade/:username' do end def require_admin - redirect '/' unless signed_in? && current_site.is_admin + redirect '/' unless is_admin? end + +def is_admin? + signed_in? && current_site.is_admin +end \ No newline at end of file diff --git a/app/browse.rb b/app/browse.rb index ca227db4..4d9bfddb 100644 --- a/app/browse.rb +++ b/app/browse.rb @@ -63,47 +63,46 @@ def browse_sites_dataset return ds end - params[:sort_by] ||= 'followers' + params[:sort_by] ||= 'special_sauce' case params[:sort_by] when 'special_sauce' - ds = ds.where{score > 1} - ds = ds.order(:score.desc, :follow_count.desc, :views.desc, :site_updated_at.desc) - when 'supporters' - ds = ds.where sites__id: Site.supporter_ids - ds = ds.order :follow_count.desc, :views.desc, :site_updated_at.desc - #when 'featured' - # ds = ds.exclude featured_at: nil - # ds = ds.order :featured_at.desc - #when 'hits' - # ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} - # ds = ds.order(:hits.desc, :site_updated_at.desc) - #when 'most_views' - # ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} - # ds = ds.order(:views.desc, :site_updated_at.desc) - #when 'least_views' - # ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} - # ds = ds.order(:views.asc, :site_updated_at.desc) - when 'newest' - ds = ds.order(:created_at.desc, :views.desc) - #when 'oldest' - # ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} - # ds = ds.order(:created_at, :views.desc) + ds = ds.where{score > 1} unless params[:tag] + ds = ds.order :score.desc, :follow_count.desc, :views.desc, :site_updated_at.desc when 'random' - ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} - ds = ds.where{score > 5} + ds = ds.where{score > 3} unless params[:tag] + puts params.inspect ds = ds.order(Sequel.lit('RANDOM()')) - #ds = ds.where 'random() < 0.01' + when 'most_followed' + ds = ds.where{views > Site::BROWSE_MINIMUM_FOLLOWER_VIEWS} + ds = ds.where{follow_count > Site::BROWSE_FOLLOWER_MINIMUM_FOLLOWS} + ds = ds.where{updated_at > Site::BROWSE_FOLLOWER_UPDATED_AT_CUTOFF.ago} unless params[:tag] + ds = ds.order :follow_count.desc, :score.desc, :updated_at.desc when 'last_updated' - ds = ds.where{score > 5} - ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} - params[:sort_by] = 'last_updated' - ds = ds.exclude(site_updated_at: nil) - ds = ds.order(:site_updated_at.desc) + ds = ds.where{score > 3} unless params[:tag] + ds = ds.exclude site_updated_at: nil + ds = ds.order :site_updated_at.desc + when 'newest' + ds = ds.where{views > Site::BROWSE_MINIMUM_VIEWS} unless is_admin? + ds = ds.exclude site_updated_at: nil + ds = ds.order :created_at.desc, :views.desc + when 'oldest' + ds = ds.where{score > 0.4} unless params[:tag] + ds = ds.exclude site_updated_at: nil + ds = ds.order(:created_at, :views.desc) + when 'hits' + ds = ds.where{score > 1} + ds = ds.order(:hits.desc, :site_updated_at.desc) + when 'views' + ds = ds.where{score > 3} + ds = ds.order(:views.desc, :site_updated_at.desc) + when 'featured' + ds = ds.exclude featured_at: nil + ds = ds.order :featured_at.desc when 'tipping_enabled' ds = ds.where tipping_enabled: true ds = ds.where("(tipping_paypal is not null and tipping_paypal != '') or (tipping_bitcoin is not null and tipping_bitcoin != '')") - ds = ds.where{views > Site::BROWSE_MINIMUM_FOLLOWER_VIEWS} + ds = ds.where{score > 1} unless params[:tag] ds = ds.group :sites__id ds = ds.order :follow_count.desc, :views.desc, :updated_at.desc when 'blocks' @@ -112,11 +111,6 @@ def browse_sites_dataset ds = ds.inner_join :blocks, :site_id => :id ds = ds.group :sites__id ds = ds.order :total.desc - when 'followers' - params[:sort_by] = 'followers' - ds = ds.where{follow_count > 0} - ds = ds.where{updated_at > 9.months.ago} - ds = ds.order :follow_count.desc, :score.desc, :updated_at.desc end ds = ds.where ['sites.is_nsfw = ?', (params[:is_nsfw] == 'true' ? true : false)] diff --git a/models/site.rb b/models/site.rb index b8c0c5e0..5a7ae69d 100644 --- a/models/site.rb +++ b/models/site.rb @@ -84,6 +84,8 @@ class Site < Sequel::Model BROWSE_MINIMUM_VIEWS = 100 BROWSE_MINIMUM_FOLLOWER_VIEWS = 10_000 + BROWSE_FOLLOWER_UPDATED_AT_CUTOFF = 9.months + BROWSE_FOLLOWER_MINIMUM_FOLLOWS = 0 SCREENSHOT_DELAY_SECONDS = 30 SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50'] diff --git a/tests/acceptance/site_tests.rb b/tests/acceptance/site_tests.rb index 5c9d58be..a7cac4e7 100644 --- a/tests/acceptance/site_tests.rb +++ b/tests/acceptance/site_tests.rb @@ -68,7 +68,7 @@ describe 'site page' do describe 'blocking' do before do @tag = SecureRandom.hex 10 - @blocked_site = Fabricate :site, new_tags_string: @tag, created_at: 2.weeks.ago, site_changed: true, views: Site::BROWSE_MINIMUM_FOLLOWER_VIEWS+1 + @blocked_site = Fabricate :site, new_tags_string: @tag, created_at: 1.year.ago, site_changed: true, views: Site::BROWSE_MINIMUM_FOLLOWER_VIEWS+1, follow_count: Site::BROWSE_FOLLOWER_MINIMUM_FOLLOWS+1 end after do diff --git a/views/browse.erb b/views/browse.erb index 798087bb..c9cfd163 100644 --- a/views/browse.erb +++ b/views/browse.erb @@ -15,18 +15,17 @@