新增:项目活跃度算法及接口

This commit is contained in:
2024-05-24 17:50:54 +08:00
parent c58ca88edd
commit 45587ad543
4 changed files with 182 additions and 1 deletions

View File

@@ -31,6 +31,61 @@ class Cache::V2::PlatformStatisticService < ApplicationService
"v2-platform-statistic"
end
# 平台最高关注数
def max_watcher_count_key
"max-watcher-count"
end
# 平台最高点赞数
def max_praise_count_key
"max-praise-count"
end
# 平台最高fork数
def max_fork_count_key
"max-fork-count"
end
# 平台最高pr数
def max_pullrequest_count_key
"max-pullrequest-count"
end
# 平台最高issue数
def max_issue_count_key
"max-issue-count"
end
# 平台最高commit数
def max_commit_count_key
"max-commit-count"
end
# 平台最高仓库人数
def max_member_count_key
"max-member-count"
end
# 平台近一个月新增成员最大值
def max_recent_one_month_member_count_key
"max-recent-one-month-member-count"
end
# 平台近一个月合并请求最大值
def max_recent_one_month_pullrequest_count_key
"max-recent-one-month-pullrequest-count"
end
# 平台近一个月issue最大值
def max_recent_one_month_issue_count_key
"max-recent-one-month-issue-count"
end
# 平台近一个月commit最大值
def max_recent_one_month_commit_count_key
"max-recent-one-month-commit-count"
end
def follow_count_key
"follow-count"
end
@@ -136,6 +191,61 @@ class Cache::V2::PlatformStatisticService < ApplicationService
$redis_cache.hgetall(platform_statistic_key)
end
def reset_platform_max_watcher_count
max_watcher = Watcher.where(watchable_type:"Project").group(:watchable_type, :watchable_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_watcher_count_key, max_watcher[1].nil? ? 0 : max_watcher[1])
end
def reset_platform_max_praise_count
max_praise = PraiseTread.where(praise_tread_object_type: "Project").group(:praise_tread_object_type, :praise_tread_object_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_praise_count_key, max_praise[1].nil? ? 0 : max_praise[1])
end
def reset_platform_max_fork_count
max_fork = ForkUser.group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_fork_count_key, max_fork[1].nil? ? 0 : max_fork[1])
end
def reset_platform_max_pullrequest_count
max_pullrequest = PullRequest.group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_pullrequest_count_key, max_pullrequest[1].nil? ? 0 : max_pullrequest[1])
end
def reset_platform_max_issue_count
max_issue = Issue.issue_issue.group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_issue_count_key, max_issue[1].nil? ? 0 : max_issue[1])
end
def reset_platform_max_commit_count
max_commit = CommitLog.joins(:project).merge(Project.common).group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_commit_count_key, max_commit[1].nil? ? 0 : max_commit[1])
end
def reset_platform_max_member_count
max_member = Member.where.not(project_id: [0,-1]).group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_member_count_key, max_member[1].nil? ? 0 : max_member[1])
end
def reset_platform_max_recent_one_month_member_count
max_recent_one_month_member = Member.where("created_on > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_recent_one_month_member_count_key, max_recent_one_month_member[1].nil? ? 0 : max_recent_one_month_member[1])
end
def reset_platform_max_recent_one_month_pullrequest_count
max_recent_one_month_pullrequest = PullRequest.where("created_at > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_recent_one_month_pullrequest_count_key, max_recent_one_month_pullrequest[1].nil? ? 0 : max_recent_one_month_pullrequest[1])
end
def reset_platform_max_recent_one_month_issue_count
max_recent_one_month_issue = Issue.issue_issue.where("created_on > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_recent_one_month_issue_count_key, max_recent_one_month_issue[1].nil? ? 0 : max_recent_one_month_issue[1])
end
def reset_platform_max_recent_one_month_commit_count
max_recent_one_month_commit = CommitLog.joins(:project).merge(Project.common).where("created_at > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || []
$redis_cache.hset(platform_statistic_key, max_recent_one_month_commit_count_key, max_recent_one_month_commit[1].nil? ? 0 : max_recent_one_month_commit[1])
end
def reset_platform_follow_count
$redis_cache.hset(platform_statistic_key, follow_count_key, Watcher.where(watchable_type: 'User').count)
end
@@ -178,6 +288,17 @@ class Cache::V2::PlatformStatisticService < ApplicationService
reset_platform_project_praise_count
reset_platform_project_watcher_count
reset_platform_pullrequest_count
reset_platform_max_watcher_count
reset_platform_max_praise_count
reset_platform_max_fork_count
reset_platform_max_pullrequest_count
reset_platform_max_issue_count
reset_platform_max_commit_count
reset_platform_max_member_count
reset_platform_max_recent_one_month_member_count
reset_platform_max_recent_one_month_pullrequest_count
reset_platform_max_recent_one_month_issue_count
reset_platform_max_recent_one_month_commit_count
$redis_cache.hgetall(platform_statistic_key)
end