index for suggestions, only load when needed

This commit is contained in:
Kyle Drake 2019-10-30 13:18:10 -07:00
parent ae3df1d0f9
commit 16673f0111
4 changed files with 11 additions and 4 deletions

View file

@ -4,8 +4,6 @@ get '/?' do
redirect '/dashboard' if current_site.is_education redirect '/dashboard' if current_site.is_education
@suggestions = current_site.suggestions
@page = params[:page].to_i @page = params[:page].to_i
@page = 1 if @page == 0 @page = 1 if @page == 0

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.add_index :sites, [:follow_count, :updated_at, :views]
}
down {
DB.drop_index :sites, [:follow_count, :updated_at, :views]
}
end

View file

@ -1466,7 +1466,7 @@ class Site < Sequel::Model
end end
def suggestions(limit=SUGGESTIONS_LIMIT, offset=0) def suggestions(limit=SUGGESTIONS_LIMIT, offset=0)
suggestions_dataset = Site.exclude(id: id).exclude(is_banned: true).exclude(is_nsfw: true).order(:views.desc, :updated_at.desc) suggestions_dataset = Site.exclude(id: id).exclude(is_deleted: true).exclude(is_nsfw: true).order(:views.desc, :updated_at.desc)
suggestions = suggestions_dataset.where(tags: tags).limit(limit, offset).all suggestions = suggestions_dataset.where(tags: tags).limit(limit, offset).all
return suggestions if suggestions.length == limit return suggestions if suggestions.length == limit

View file

@ -48,7 +48,7 @@
<% if site.followings_dataset.count == 0 %> <% if site.followings_dataset.count == 0 %>
<% if !@events.empty? %><h2>Sites to Follow</h2><% end %> <% if !@events.empty? %><h2>Sites to Follow</h2><% end %>
<ul class="row website-Gallery content int-Gall suggestions"> <ul class="row website-Gallery content int-Gall suggestions">
<% @suggestions.each do |suggested_site| %> <% current_site.suggestions.each do |suggested_site| %>
<li> <li>
<a href="<%= suggested_site.uri %>" class="neo-Screen-Shot" title="<%= suggested_site.title %>"> <a href="<%= suggested_site.uri %>" class="neo-Screen-Shot" title="<%= suggested_site.title %>">
<span class="img-Holder" style="background:url(<%= suggested_site.screenshot_url('index.html', '540x405') %>) no-repeat;"> <span class="img-Holder" style="background:url(<%= suggested_site.screenshot_url('index.html', '540x405') %>) no-repeat;">