Merge branch 'pre_trustie_server' into trustie_server

This commit is contained in:
2023-02-03 14:12:23 +08:00
14 changed files with 220 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
class Api::V1::Projects::CodeStats::ListService < ApplicationService
attr_reader :project, :ref, :owner, :repo, :token
attr_reader :project, :ref, :owner, :repo, :token, :page, :limit
attr_accessor :gitea_data
def initialize(project, params, token=nil)

View File

@@ -28,6 +28,10 @@ class Cache::V2::ProjectDateRankService < ApplicationService
"v2-project-rank-#{@rank_date.to_s}"
end
def project_rank_statistic_key
"v2-project-statistic:#{@project_id}-#{@rank_date.to_s}"
end
def project_rank
$redis_cache.zscore(project_rank_key, @project_id)
end
@@ -35,26 +39,37 @@ class Cache::V2::ProjectDateRankService < ApplicationService
def set_project_rank
if @visits.present?
$redis_cache.zincrby(project_rank_key, @visits.to_i * 1, @project_id)
$redis_cache.hincrby(project_rank_statistic_key, "visits", @visits.to_i)
end
if @watchers.present?
$redis_cache.zincrby(project_rank_key, @watchers.to_i * 5, @project_id)
$redis_cache.hincrby(project_rank_statistic_key, "watchers", @watchers.to_i)
end
if @praises.present?
$redis_cache.zincrby(project_rank_key, @praises.to_i * 5, @project_id)
$redis_cache.hincrby(project_rank_statistic_key, "praises", @praises.to_i)
end
if @forks.present?
$redis_cache.zincrby(project_rank_key, @forks.to_i * 10, @project_id)
$redis_cache.hincrby(project_rank_statistic_key, "forks", @forks.to_i)
end
if @issues.present?
$redis_cache.zincrby(project_rank_key, @issues.to_i * 5, @project_id)
$redis_cache.hincrby(project_rank_statistic_key, "issues", @issues.to_i)
end
if @pullrequests.present?
$redis_cache.zincrby(project_rank_key, @pullrequests.to_i * 10, @project_id)
$redis_cache.hincrby(project_rank_statistic_key, "pullrequests", @pullrequests.to_i)
end
if @commits.present?
$redis_cache.zincrby(project_rank_key, @commits.to_i * 5, @project_id)
$redis_cache.hincrby(project_rank_statistic_key, "commits", @commits.to_i)
end
$redis_cache.zscore(project_rank_key, @project_id)
# 设置过期时间(一个月)
$redis_cache.expireat(project_rank_key, (@rank_date+30.days).to_time.to_i)
$redis_cache.expireat(project_rank_statistic_key, (@rank_date+30.days).to_time.to_i)
end
end

View File

@@ -115,5 +115,9 @@ class Cache::V2::UserDateRankService < ApplicationService
$redis_cache.zadd(user_rank_key, score-300, @user_id) if score > 300
$redis_cache.zscore(user_rank_key, @user_id)
# 设置过期时间(一个月)
$redis_cache.expireat(user_rank_key, (@rank_date+30.days).to_time.to_i)
$redis_cache.expireat(user_date_statistic_key, (@rank_date+30.days).to_time.to_i)
end
end

View File

@@ -29,7 +29,7 @@ class Projects::ForkService < ApplicationService
ProjectUnit.init_types(clone_project.id)
@project.update_column('forked_count', @project&.forked_count.to_i + 1)
@project.update_attribute('forked_count', @project&.forked_count.to_i + 1)
new_repository.update_column('url', result['clone_url']) if result
ForkUser.create(project_id: @project.id, fork_project_id: clone_project.id, user_id: clone_project.user_id)