mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
add: project rank and user rank api
This commit is contained in:
14
app/services/cache/v2/owner_common_service.rb
vendored
14
app/services/cache/v2/owner_common_service.rb
vendored
@@ -31,6 +31,10 @@ class Cache::V2::OwnerCommonService < ApplicationService
|
||||
"v2-owner-common:#{@login}-#{@email.to_s}"
|
||||
end
|
||||
|
||||
def owner_common_key_by_id
|
||||
"v2-owner-common:#{@owner.id}"
|
||||
end
|
||||
|
||||
def owner_common
|
||||
$redis_cache.hgetall(owner_common_key).blank? ? reset_owner_common : $redis_cache.hgetall(owner_common_key)
|
||||
end
|
||||
@@ -46,6 +50,9 @@ class Cache::V2::OwnerCommonService < ApplicationService
|
||||
else
|
||||
$redis_cache.hset(owner_common_key, "name", @name)
|
||||
$redis_cache.hset(owner_common_key, "avatar_url", url_to_avatar(owner))
|
||||
|
||||
$redis_cache.hset(owner_common_key_by_id, "name", @name)
|
||||
$redis_cache.hset(owner_common_key_by_id, "avatar_url", url_to_avatar(owner))
|
||||
end
|
||||
end
|
||||
if @email.present?
|
||||
@@ -53,6 +60,7 @@ class Cache::V2::OwnerCommonService < ApplicationService
|
||||
reset_owner_email
|
||||
else
|
||||
$redis_cache.hset(owner_common_key, "email", @email)
|
||||
$redis_cache.hset(owner_common_key_by_id, "email", @email)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,23 +68,29 @@ class Cache::V2::OwnerCommonService < ApplicationService
|
||||
end
|
||||
def reset_owner_id
|
||||
$redis_cache.hset(owner_common_key, "id", owner&.id)
|
||||
$redis_cache.hset(owner_common_key_by_id, "id", owner&.id)
|
||||
end
|
||||
|
||||
def reset_owner_type
|
||||
$redis_cache.hset(owner_common_key, "type", owner&.type)
|
||||
$redis_cache.hset(owner_common_key_by_id, "type", owner&.type)
|
||||
end
|
||||
|
||||
def reset_owner_login
|
||||
$redis_cache.hset(owner_common_key, "login", owner&.login)
|
||||
$redis_cache.hset(owner_common_key_by_id, "login", owner&.login)
|
||||
end
|
||||
|
||||
def reset_owner_email
|
||||
$redis_cache.hset(owner_common_key, "email", owner&.mail)
|
||||
$redis_cache.hset(owner_common_key_by_id, "email", owner&.mail)
|
||||
end
|
||||
|
||||
def reset_owner_name
|
||||
$redis_cache.hset(owner_common_key, "name", owner&.real_name)
|
||||
$redis_cache.hset(owner_common_key, "avatar_url", url_to_avatar(owner))
|
||||
$redis_cache.hset(owner_common_key_by_id, "name", owner&.real_name)
|
||||
$redis_cache.hset(owner_common_key_by_id, "avatar_url", url_to_avatar(owner))
|
||||
end
|
||||
|
||||
def reset_owner_common
|
||||
|
||||
@@ -120,7 +120,10 @@ class Cache::V2::ProjectCommonService < ApplicationService
|
||||
Cache::V2::ProjectRankService.call(@project_id, {visits: @visits})
|
||||
Cache::V2::ProjectDateRankService.call(@project_id, Date.today, {visits: @visits})
|
||||
else
|
||||
$redis_cache.hincrby(project_common_key, visits_key, @visits)
|
||||
puts project_common_key
|
||||
puts visits_key
|
||||
puts @visits
|
||||
$redis_cache.hincrby(project_common_key, visits_key, @visits.to_s)
|
||||
Cache::V2::ProjectRankService.call(@project_id, {visits: @visits})
|
||||
Cache::V2::ProjectDateRankService.call(@project_id, Date.today, {visits: @visits})
|
||||
end
|
||||
@@ -196,7 +199,7 @@ class Cache::V2::ProjectCommonService < ApplicationService
|
||||
end
|
||||
|
||||
def reset_project_visits
|
||||
$redis_cache.hset(project_common_key, visits_key, @project&.visits)
|
||||
$redis_cache.hset(project_common_key, visits_key, @project&.visits || 0)
|
||||
end
|
||||
|
||||
def reset_project_watchers
|
||||
|
||||
10
app/services/cache/v2/project_rank_service.rb
vendored
10
app/services/cache/v2/project_rank_service.rb
vendored
@@ -37,6 +37,7 @@ class Cache::V2::ProjectRankService < ApplicationService
|
||||
end
|
||||
|
||||
def set_project_rank
|
||||
load_project_common
|
||||
if $redis_cache.zscore(project_rank_key, @project_id).blank?
|
||||
reset_project_rank
|
||||
return
|
||||
@@ -56,16 +57,21 @@ class Cache::V2::ProjectRankService < ApplicationService
|
||||
if @pullrequests.present?
|
||||
$redis_cache.zincrby(project_rank_key, @pullrequests.to_i * 10, @project_id)
|
||||
end
|
||||
reset_user_project_rank
|
||||
|
||||
$redis_cache.zscore(project_rank_key, @project_id)
|
||||
end
|
||||
|
||||
def reset_project_rank
|
||||
load_project_common
|
||||
$redis_cache.zrem(project_rank_key, @project_id)
|
||||
score = @project_common["visits"].to_i * 1 + @project_common["praises"].to_i * 5 + @project_common["forks"].to_i * 5 + @project_common["issues"].to_i * 10 + @project_common["pullrequests"].to_i * 10
|
||||
$redis_cache.zincrby(project_rank_key, score, @project_id)
|
||||
$redis_cache.zadd(project_rank_key, score, @project_id)
|
||||
reset_user_project_rank
|
||||
|
||||
$redis_cache.zscore(project_rank_key, @project_id)
|
||||
end
|
||||
|
||||
def reset_user_project_rank
|
||||
$redis_cache.zadd("v2-user-project-rank:#{@project_common["owner_id"]}", $redis_cache.zscore(project_rank_key, @project_id), @project_id)
|
||||
end
|
||||
end
|
||||
@@ -93,7 +93,8 @@ class Cache::V2::UserDateRankService < ApplicationService
|
||||
fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0
|
||||
project_watchers_count = $redis_cache.hget(user_date_statistic_key, "project-watcher-count") || 0
|
||||
project_praises_count = $redis_cache.hget(user_date_statistic_key, "project-praise-count") || 0
|
||||
project_languages_count = $redis_cache.hget(user_date_statistic_key, "project-language").nil? ? 0 : $redis_cache.hget(user_date_statistic_key, "project-language").length
|
||||
project_language = $redis_cache.hget(user_date_statistic_key, "project-language")
|
||||
project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length
|
||||
# 影响力
|
||||
influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i
|
||||
|
||||
@@ -110,8 +111,8 @@ class Cache::V2::UserDateRankService < ApplicationService
|
||||
language = (60.0 + project_languages_count.to_i / (project_languages_count.to_i + 5.0) * 40.0).to_i
|
||||
|
||||
score = influence+ contribution + activity + experience + language
|
||||
|
||||
$redis_cache.zadd(user_rank_key, score, @user_id) if score.to_i > 300
|
||||
$redis_cache.zrem(user_rank_key, @user_id)
|
||||
$redis_cache.zadd(user_rank_key, score-300, @user_id) if score > 300
|
||||
|
||||
$redis_cache.zscore(user_rank_key, @user_id)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user