further refinements to browse, fix broken test

This commit is contained in:
Kyle Drake 2024-08-14 11:15:45 -05:00
parent 18102eb76b
commit 4fc5698d0e
5 changed files with 50 additions and 51 deletions

View file

@ -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)]