mirror of
https://github.com/neocities/neocities.git
synced 2025-08-04 08:42:00 +02:00
speed up and improve global activity
This commit is contained in:
parent
a00d460ce0
commit
a67588a1c0
4 changed files with 20 additions and 114 deletions
|
@ -13,9 +13,9 @@ class Event < Sequel::Model
|
|||
many_to_one :site
|
||||
many_to_one :actioning_site, key: :actioning_site_id, class: :Site
|
||||
|
||||
DEFAULT_GLOBAL_LIMIT = 300
|
||||
GLOBAL_VIEWS_MINIMUM = 5
|
||||
GLOBAL_VIEWS_SITE_CHANGE_MINIMUM = 3_000
|
||||
PAGINATION_LENGTH = 10
|
||||
GLOBAL_PAGINATION_LENGTH = 20
|
||||
GLOBAL_SCORE_LIMIT = 3
|
||||
|
||||
def undeleted_comments_count
|
||||
comments_dataset.exclude(is_deleted: true).count
|
||||
|
@ -26,43 +26,18 @@ class Event < Sequel::Model
|
|||
end
|
||||
|
||||
def self.news_feed_default_dataset
|
||||
if SimpleCache.expired?(:excluded_actioning_site_ids)
|
||||
res = DB[%{select distinct(actioning_site_id) from events join sites on actioning_site_id=sites.id where sites.is_deleted='t'}].all.collect {|r| r[:actioning_site_id]}
|
||||
excluded_actioning_site_ids = SimpleCache.store :excluded_actioning_site_ids, res, 2.hours
|
||||
else
|
||||
excluded_actioning_site_ids = SimpleCache.get :excluded_actioning_site_ids
|
||||
end
|
||||
|
||||
ds = select_all(:events).
|
||||
order(:created_at.desc).
|
||||
join_table(:inner, :sites, id: :site_id).
|
||||
where(follow_id: nil).
|
||||
exclude(Sequel.qualify(:sites, :is_deleted) => true).
|
||||
exclude(Sequel.qualify(:events, :is_deleted) => true).
|
||||
exclude(is_banned: true)
|
||||
|
||||
unless excluded_actioning_site_ids.empty?
|
||||
return ds.where("actioning_site_id is null or actioning_site_id not in ?", excluded_actioning_site_ids)
|
||||
end
|
||||
|
||||
ds
|
||||
select(:events.*).
|
||||
join(:sites, id: :site_id).
|
||||
order(:created_at.desc).
|
||||
exclude(events__is_deleted: true).
|
||||
exclude(sites__is_deleted: true).
|
||||
exclude(is_nsfw: true).
|
||||
exclude(is_crashing: true).
|
||||
where(follow_id: nil)
|
||||
end
|
||||
|
||||
def self.global_dataset(current_page=1, limit=DEFAULT_GLOBAL_LIMIT)
|
||||
news_feed_default_dataset.
|
||||
paginate(current_page.to_i, 100).
|
||||
exclude(is_nsfw: true).
|
||||
exclude(is_crashing: true).
|
||||
where{views > GLOBAL_VIEWS_MINIMUM}.
|
||||
where(site_change_id: nil)
|
||||
end
|
||||
|
||||
def self.global_site_changes_dataset
|
||||
news_feed_default_dataset.
|
||||
where{views > GLOBAL_VIEWS_SITE_CHANGE_MINIMUM}.
|
||||
exclude(is_nsfw: true).
|
||||
exclude(is_crashing: true).
|
||||
exclude(site_change_id: nil)
|
||||
def self.global_dataset
|
||||
news_feed_default_dataset.where{score > GLOBAL_SCORE_LIMIT}
|
||||
end
|
||||
|
||||
def created_by?(site)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue