Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
xxq250 2023-04-17 11:08:51 +08:00
commit 5a2659253e
12 changed files with 327 additions and 248 deletions

View File

@ -19,9 +19,10 @@ class CommitLogsController < ApplicationController
params[:commits].each do |commit|
commit_id = commit[:id]
message = commit[:message]
CommitLog.create(user: user, project: project, repository_id: repository_id,
commit_log = CommitLog.create(user: user, project: project, repository_id: repository_id,
name: repository_name, full_name: repository_full_name,
ref: ref, commit_id: commit_id, message: message)
commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create")
# 统计数据新增
CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id)
end

View File

@ -1,10 +1,13 @@
class ProjectRankController < ApplicationController
# 根据时间获取热门项目
def index
limit = 9
limit = params[:limit].to_i - 1 if params[:limit].present?
limit = 99 if limit > 99
$redis_cache.zunionstore("recent-days-project-rank-#{time}", get_timeable_key_names)
deleted_data = $redis_cache.smembers("v2-project-rank-deleted")
$redis_cache.zrem("recent-days-project-rank-#{time}", deleted_data) unless deleted_data.blank?
@project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, 9, withscores: true)
@project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, limit, withscores: true)
rescue Exception => e
@project_rank = []
end

View File

@ -1,6 +1,6 @@
class ProjectTrendsController < ApplicationController
before_action :load_repository
before_action :check_project_public
before_action :load_repository, except: [:last]
before_action :check_project_public, except: [:last]
def index
project_trends = @project.project_trends.preload(:user, trend: :user, project: :owner)
@ -42,6 +42,14 @@ class ProjectTrendsController < ApplicationController
@project_trends = project_trends.page(@page).per(@limit)
end
def last
project_trends = ProjectTrend.preload(:user, trend: :user, project: :owner).order("id desc")
@page = params[:page] || 1
@limit = params[:limit] || 20
@project_trends_count = project_trends.count
@project_trends = project_trends.page(@page).per(@limit)
end
private
def check_project_public

View File

@ -1,8 +1,11 @@
class UserRankController < ApplicationController
# 根据时间获取热门开发者
def index
limit = 3
limit = params[:limit].to_i - 1 if params[:limit].present?
limit = 99 if limit > 99
$redis_cache.zunionstore("recent-days-user-rank", get_timeable_key_names)
@user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, 3, withscores: true)
@user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, limit, withscores: true)
rescue Exception => e
@user_rank = []
end

View File

@ -3,4 +3,10 @@ class CommitLog < ApplicationRecord
belongs_to :project
belongs_to :repository
has_many :project_trends, as: :trend, dependent: :destroy
def title
self.message
end
end

View File

@ -29,3 +29,5 @@ json.watchers project_common["watchers"]
json.praises project_common["praises"]
json.issues project_common["issues"]
json.pulls project_common["pullrequests"]
json.commits project_common["commits"]
json.issues project_common["issues"]

View File

@ -18,6 +18,15 @@ if trend.trend_type == "Issue"
json.partial! "issues/simple_issue_item", locals: {issue: trend.trend}
elsif trend.trend_type == "VersionRelease"
json.partial! "version_releases/simple_version_release", locals: {version: trend.trend}
elsif trend.trend_type == "CommitLog"
json.commit_log do
commit_log = trend.trend
json.user do
json.partial! 'users/user_simple', locals: {user: commit_log.user}
end
json.ref commit_log.ref.to_s.gsub("refs/heads/", "")
json.extract! commit_log, :id,:name,:full_name,:message, :commit_id,:created_at,:updated_at
end
else
json.name trend.trend&.title
json.created_at format_time(trend.trend&.created_at)

View File

@ -0,0 +1,8 @@
json.partial! "commons/success"
json.total_count @project_trends_count
json.project_trends do
json.array! @project_trends.to_a.each do |trend|
json.partial! "detail", trend: trend
end
end

View File

@ -19,3 +19,33 @@ else
json.description popular_project_common["description"]
end
end
ids = $redis_cache.zrevrange("v2-user-project-rank:#{item[0]}", 0, 999, withscores: true).map{|a|a[0]}
visits = 0
forks = 0
watchers = 0
praises = 0
issues = 0
pulls = 0
commits = 0
issues = 0
ids.each do |pid|
project_common = $redis_cache.hgetall("v2-project-common:#{pid}")
visits = visits + project_common["visits"].to_i
forks = forks + project_common["forks"].to_i
watchers = watchers + project_common["watchers"].to_i
praises = praises + project_common["praises"].to_i
issues = issues + project_common["issues"].to_i
pulls = pulls + project_common["pullrequests"].to_i
commits = commits + project_common["commits"].to_i
issues = issues + project_common["issues"].to_i
end
json.visits visits
json.forks forks
json.watchers watchers
json.praises praises
json.issues issues
json.pulls pulls
json.commits commits
json.issues issues

View File

@ -18,6 +18,7 @@ zh-CN:
Issue: 疑修(Issue)
PullRequest: 合并请求(PR)
VersionRelease: 版本发布
CommitLog: 代码(Commit)
create: 创建了
journal: 回复了
close: 关闭了

View File

@ -117,6 +117,7 @@ Rails.application.routes.draw do
get 'home/index'
get 'home/search'
get 'main/first_stamp'
get 'activity/last', to: 'project_trends#last'
get 'search', to: 'searchs#index'
put 'commons/hidden', to: 'commons#hidden'
@ -763,6 +764,7 @@ Rails.application.routes.draw do
end
end
end
# Project Area END
scope module: :helps do

View File

@ -0,0 +1,6 @@
class UpdateCommitLogUtf8 < ActiveRecord::Migration[5.2]
def change
execute("ALTER TABLE `commit_logs` MODIFY `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `commit_logs` MODIFY `full_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
end
end