mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
use one query to get tag names for sites in browse
This commit is contained in:
parent
2b69e9cb8a
commit
f9c885c23b
2 changed files with 11 additions and 3 deletions
|
@ -15,6 +15,14 @@ get '/browse/?' do
|
|||
@pagination_dataset = site_dataset
|
||||
@sites = site_dataset.all
|
||||
|
||||
site_ids = @sites.collect {|s| s[:id]}
|
||||
tags = DB['select site_id,name from tags join sites_tags on tags.id=sites_tags.tag_id where site_id IN ?', site_ids].all
|
||||
|
||||
@site_tags = {}
|
||||
site_ids.each do |site_id|
|
||||
@site_tags[site_id] = tags.select {|t| t[:site_id] == site_id}.collect {|t| t[:name]}
|
||||
end
|
||||
|
||||
if params[:tag]
|
||||
@title = "Sites tagged #{params[:tag]}"
|
||||
end
|
||||
|
|
|
@ -116,10 +116,10 @@
|
|||
</a>
|
||||
</div>
|
||||
<div class="site-tags">
|
||||
<% if site.tags.count > 0 %>
|
||||
<% if @site_tags[site.id].length > 0 %>
|
||||
<i class="fa fa-tag"></i>
|
||||
<% site.tags.each_with_index do |tag, index| %>
|
||||
<a class="" href="/browse?tag=<%= Rack::Utils.escape tag.name %>"><%= tag.name %></a><% if index != site.tags.length - 1 %>,<% end %>
|
||||
<% @site_tags[site.id].each_with_index do |tag, index| %>
|
||||
<a class="" href="/browse?tag=<%= Rack::Utils.escape tag %>"><%= tag %></a><% if index != @site_tags[site.id].length - 1 %>,<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue