Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
“xxq250” 2022-09-26 10:38:32 +08:00
commit ae0efc1115
7 changed files with 64 additions and 7 deletions

View File

@ -11,6 +11,7 @@ module Repository::LanguagesPercentagable
end
def update_project_language(language)
return if @project.project_language.present?
db_language = ProjectLanguage.find_or_create_by!(name: language.keys.first.downcase.upcase_first)
@project.update_column(:project_language_id, db_language.id)
rescue

View File

@ -47,8 +47,13 @@ class RepositoriesController < ApplicationController
end
def entries
@project.increment!(:visits)
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
@week_project_visit_record, @month_project_visit_record = TimeableVisitRecord.build(@project.id)
if @week_project_visit_record.visits < 300 && @month_project_visit_record.visits < 1000
@week_project_visit_record.increment!(:visits)
@month_project_visit_record.increment!(:visits)
@project.increment!(:visits)
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
end
if @project.educoder?
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
else

View File

@ -0,0 +1,28 @@
# == Schema Information
#
# Table name: timeable_visit_records
#
# id :integer not null, primary key
# time :string(255)
# project_id :integer
# visits :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_timeable_visit_records_on_project_id (project_id)
# index_timeable_visit_records_on_time (time)
#
class TimeableVisitRecord < ApplicationRecord
belongs_to :project
def self.build(project_id)
week = TimeableVisitRecord.find_or_create_by!(time: Date.today.strftime("%Y-%W"), project_id: project_id)
month = TimeableVisitRecord.find_or_create_by!(time: Date.today.strftime("%Y%m"), project_id: project_id)
return week, month
end
end

View File

@ -133,6 +133,8 @@ class Cache::V2::ProjectCommonService < ApplicationService
end
if @watchers.present?
$redis_cache.hincrby(project_common_key, watchers_key, @watchers)
Cache::V2::ProjectRankService.call(@project_id, {watchers: @watchers})
Cache::V2::ProjectDateRankService.call(@project_id, Date.today, {watchers: @watchers})
end
if @praises.present?
$redis_cache.hincrby(project_common_key, praises_key, @praises)

View File

@ -7,6 +7,7 @@ class Cache::V2::ProjectDateRankService < ApplicationService
@project_id = project_id
@rank_date = rank_date
@visits = params[:visits]
@watchers = params[:watchers]
@praises = params[:praises]
@forks = params[:forks]
@issues = params[:issues]
@ -35,6 +36,9 @@ class Cache::V2::ProjectDateRankService < ApplicationService
if @visits.present?
$redis_cache.zincrby(project_rank_key, @visits.to_i * 1, @project_id)
end
if @watchers.present?
$redis_cache.zincrby(project_rank_key, @watchers.to_i * 5, @project_id)
end
if @praises.present?
$redis_cache.zincrby(project_rank_key, @praises.to_i * 5, @project_id)
end
@ -42,13 +46,13 @@ class Cache::V2::ProjectDateRankService < ApplicationService
$redis_cache.zincrby(project_rank_key, @forks.to_i * 10, @project_id)
end
if @issues.present?
$redis_cache.zincrby(project_rank_key, @issues.to_i * 10, @project_id)
$redis_cache.zincrby(project_rank_key, @issues.to_i * 5, @project_id)
end
if @pullrequests.present?
$redis_cache.zincrby(project_rank_key, @pullrequests.to_i * 10, @project_id)
end
if @commits.present?
$redis_cache.zincrby(project_rank_key, @commits.to_i * 1, @project_id)
$redis_cache.zincrby(project_rank_key, @commits.to_i * 5, @project_id)
end
$redis_cache.zscore(project_rank_key, @project_id)

View File

@ -5,6 +5,7 @@ class Cache::V2::ProjectRankService < ApplicationService
def initialize(project_id, params={})
@project_id = project_id
@visits = params[:visits]
@watchers = params[:watchers]
@praises = params[:praises]
@forks = params[:forks]
@issues = params[:issues]
@ -51,6 +52,9 @@ class Cache::V2::ProjectRankService < ApplicationService
if @visits.present?
$redis_cache.zincrby(project_rank_key, @visits.to_i * 1, @project_id)
end
if @watchers.present?
$redis_cache.zincrby(project_rank_key, @watchers.to_i * 5, @project_id)
end
if @praises.present?
$redis_cache.zincrby(project_rank_key, @praises.to_i * 5, @project_id)
end
@ -58,13 +62,13 @@ class Cache::V2::ProjectRankService < ApplicationService
$redis_cache.zincrby(project_rank_key, @forks.to_i * 10, @project_id)
end
if @issues.present?
$redis_cache.zincrby(project_rank_key, @issues.to_i * 10, @project_id)
$redis_cache.zincrby(project_rank_key, @issues.to_i * 5, @project_id)
end
if @pullrequests.present?
$redis_cache.zincrby(project_rank_key, @pullrequests.to_i * 10, @project_id)
end
if @commits.present?
$redis_cache.zincrby(project_rank_key, @commits.to_i * 1, @project_id)
$redis_cache.zincrby(project_rank_key, @commits.to_i * 5, @project_id)
end
reset_user_project_rank
end
@ -74,7 +78,7 @@ class Cache::V2::ProjectRankService < ApplicationService
def reset_project_rank
load_project_common
score = @project_common["visits"].to_i * 1 + @project_common["praises"].to_i * 5 + @project_common["forks"].to_i * 10 + @project_common["issues"].to_i * 10 + @project_common["pullrequests"].to_i * 10 + @project_common["commits"].to_i * 1
score = @project_common["visits"].to_i * 1 + @project_common["watchers"].to_i * 5 + @project_common["praises"].to_i * 5 + @project_common["forks"].to_i * 10 + @project_common["issues"].to_i * 5 + @project_common["pullrequests"].to_i * 10 + @project_common["commits"].to_i * 5
$redis_cache.zadd(project_rank_key, score, @project_id)
reset_user_project_rank

View File

@ -0,0 +1,13 @@
class CreateTimeableVisitRecords < ActiveRecord::Migration[5.2]
def change
create_table :timeable_visit_records do |t|
t.string :time
t.references :project
t.integer :visits, default: 0
t.timestamps
end
add_index :timeable_visit_records, :time
end
end