discourse/lib/statistics.rb
Vinoth Kannan 9dc6325821
DEV: add logo URL and locale details to the Discover stats. (#26320)
We will be collecting the logo URL and the site's default locale values along with existing basic details to display the site on the Discourse Discover listing page. It will be included only if the site is opted-in by enabling the "`include_in_discourse_discover`" site setting.

Also, we no longer going to use `about.json` and `site/statistics.json` endpoints retrieve these data. We will be using only the `site/basic-info.json` endpoint.
2024-04-04 00:22:28 +05:30

51 lines
1.6 KiB
Ruby

# frozen_string_literal: true
class Statistics
def self.active_users
{
last_day: User.where("last_seen_at > ?", 1.days.ago).count,
"7_days": User.where("last_seen_at > ?", 7.days.ago).count,
"30_days": User.where("last_seen_at > ?", 30.days.ago).count,
}
end
def self.likes
{
last_day:
UserAction.where(action_type: UserAction::LIKE).where("created_at > ?", 1.days.ago).count,
"7_days":
UserAction.where(action_type: UserAction::LIKE).where("created_at > ?", 7.days.ago).count,
"30_days":
UserAction.where(action_type: UserAction::LIKE).where("created_at > ?", 30.days.ago).count,
count: UserAction.where(action_type: UserAction::LIKE).count,
}
end
def self.posts
{
last_day: Post.where("created_at > ?", 1.days.ago).count,
"7_days": Post.where("created_at > ?", 7.days.ago).count,
"30_days": Post.where("created_at > ?", 30.days.ago).count,
count: Post.count,
}
end
def self.topics
{
last_day: Topic.listable_topics.where("created_at > ?", 1.days.ago).count,
"7_days": Topic.listable_topics.where("created_at > ?", 7.days.ago).count,
"30_days": Topic.listable_topics.where("created_at > ?", 30.days.ago).count,
count: Topic.listable_topics.count,
}
end
def self.users
{
last_day: User.real.where("created_at > ?", 1.days.ago).count,
"7_days": User.real.where("created_at > ?", 7.days.ago).count,
"30_days": User.real.where("created_at > ?", 30.days.ago).count,
count: User.real.count,
}
end
end