mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
new approach: compute score separately from real follower count, use db cache for score rather than total
This commit is contained in:
parent
a5b71c4396
commit
bd23c94b65
3 changed files with 27 additions and 16 deletions
15
Rakefile
15
Rakefile
|
@ -422,12 +422,15 @@ task :shard_migration => [:environment] do
|
|||
FileUtils.mv './public/newtestsites', './public/testsites'
|
||||
end
|
||||
|
||||
desc 'prime_follow_count'
|
||||
task :prime_follow_count => [:environment] do
|
||||
DB['update sites set follow_count=0'].first
|
||||
Site.select(:id,:username).all.each do |site|
|
||||
count = site.follows_dataset.count
|
||||
next if count == 0
|
||||
desc 'compute_follow_count_scores'
|
||||
task :compute_follow_count_scores => [:environment] do
|
||||
|
||||
Site.select(:id,:username,:follow_count).all.each do |site|
|
||||
count = site.scorable_follow_count
|
||||
|
||||
if count != 0
|
||||
puts "#{site.username} #{site.follow_count} => #{count}"
|
||||
end
|
||||
DB['update sites set follow_count=? where id=?', count, site.id].first
|
||||
end
|
||||
end
|
||||
|
|
|
@ -351,28 +351,35 @@ class Site < Sequel::Model
|
|||
return false
|
||||
end
|
||||
|
||||
def can_follow?(site)
|
||||
return false if site.id == self.id # Do not follow yourself
|
||||
return false if site.owned_by?(self) # Do not follow your own sites
|
||||
# return false if account_sites_follow?(site) # Do not follow if any of your other sites follow
|
||||
def scorable_follow?(site)
|
||||
return false if site.id == self.id # Do not count follow of yourself
|
||||
return false if site.owned_by?(self) # Do not count follow of your own sites
|
||||
return false if account_sites_follow?(site) # Do not count follow if any of your other sites follow
|
||||
true
|
||||
end
|
||||
|
||||
def scorable_follow_count
|
||||
score_follow_count = 0
|
||||
|
||||
follows_dataset.all.each do |follow|
|
||||
score_follow_count += 1 if scorable_follow?(follow.actioning_site)
|
||||
end
|
||||
score_follow_count
|
||||
end
|
||||
|
||||
def toggle_follow(site)
|
||||
if is_following? site
|
||||
DB.transaction do
|
||||
follow = followings_dataset.filter(site_id: site.id).first
|
||||
site.events_dataset.filter(follow_id: follow.id).delete
|
||||
follow.delete
|
||||
DB['update sites set follow_count=follow_count-1 where id=?', site.id].first
|
||||
DB['update sites set follow_count=follow_count-1 where id=?', site.id].first if scorable_follow?(site)
|
||||
end
|
||||
false
|
||||
else
|
||||
return false unless can_follow?(site)
|
||||
|
||||
DB.transaction do
|
||||
follow = add_following site_id: site.id
|
||||
DB['update sites set follow_count=follow_count+1 where id=?', site.id].first
|
||||
DB['update sites set follow_count=follow_count+1 where id=?', site.id].first if scorable_follow?(site)
|
||||
Event.create site_id: site.id, actioning_site_id: self.id, follow_id: follow.id
|
||||
end
|
||||
|
||||
|
|
|
@ -26,9 +26,10 @@
|
|||
<p><a href="<%= site.latest_archive.url %>" style="margin-right: 5px"><%= site.latest_archive.ipfs_hash %></a><small style="font-size: 7pt"><a href="/permanent-web">(what is this?)</a></small></p>
|
||||
<% end %>
|
||||
-->
|
||||
<% follow_count = site.follows.count %>
|
||||
<div class="stats">
|
||||
<div class="stat"><strong><%= site.views.format_large_number %></strong> <span>view<%= site.views == 1 ? '' : 's' %></span></div>
|
||||
<div class="stat"><strong><%= site.follow_count.format_large_number %></strong> <span>follower<%= site.follow_count == 1 ? '' : 's' %></span></div>
|
||||
<div class="stat"><strong><%= follow_count.format_large_number %></strong> <span>follower<%= follow_count == 1 ? '' : 's' %></span></div>
|
||||
<div class="stat"><strong><%= site.changed_count.format_large_number %></strong> <span>update<%= site.changed_count == 1 ? '' : 's' %></span></div>
|
||||
<div class="stat tips"><strong><%= site.tips_dataset.count %></strong> <span>tips</span></div>
|
||||
</div>
|
||||
|
@ -41,7 +42,7 @@
|
|||
<a href="/site/<%= site.username %>/archives" class="btn-Action edit"><i class="fa fa-history" title="Archives"></i> Archives</a>
|
||||
<% end %>
|
||||
|
||||
<% if current_site && current_site != site && current_site.can_follow?(site) %>
|
||||
<% if current_site && current_site != site %>
|
||||
<% is_following = current_site.is_following?(site) %>
|
||||
|
||||
<a id="followLink" href="#" onclick="Site.toggleFollow(<%= site.id %>, '<%= csrf_token %>'); return false" class="btn-Action <%= is_following ? 'is-following' : '' %>">
|
||||
|
|
Loading…
Add table
Reference in a new issue