diff --git a/app/controllers/commit_logs_controller.rb b/app/controllers/commit_logs_controller.rb index cc071340e..b034f673c 100644 --- a/app/controllers/commit_logs_controller.rb +++ b/app/controllers/commit_logs_controller.rb @@ -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 diff --git a/app/controllers/project_rank_controller.rb b/app/controllers/project_rank_controller.rb index 5cea074fb..424f3ced5 100644 --- a/app/controllers/project_rank_controller.rb +++ b/app/controllers/project_rank_controller.rb @@ -1,10 +1,13 @@ class ProjectRankController < ApplicationController # 根据时间获取热门项目 - def index + 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 diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index f283d05f7..4c0b2348f 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -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 diff --git a/app/controllers/user_rank_controller.rb b/app/controllers/user_rank_controller.rb index dddca485c..1d1a7b4f3 100644 --- a/app/controllers/user_rank_controller.rb +++ b/app/controllers/user_rank_controller.rb @@ -1,8 +1,11 @@ class UserRankController < ApplicationController # 根据时间获取热门开发者 - def index + 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 diff --git a/app/models/commit_log.rb b/app/models/commit_log.rb index 9b51b0631..def2846fa 100644 --- a/app/models/commit_log.rb +++ b/app/models/commit_log.rb @@ -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 diff --git a/app/views/project_rank/_detail.json.jbuilder b/app/views/project_rank/_detail.json.jbuilder index 5e45f518e..d5b4b016b 100644 --- a/app/views/project_rank/_detail.json.jbuilder +++ b/app/views/project_rank/_detail.json.jbuilder @@ -28,4 +28,6 @@ json.forks project_common["forks"] json.watchers project_common["watchers"] json.praises project_common["praises"] json.issues project_common["issues"] -json.pulls project_common["pullrequests"] \ No newline at end of file +json.pulls project_common["pullrequests"] +json.commits project_common["commits"] +json.issues project_common["issues"] \ No newline at end of file diff --git a/app/views/project_trends/_detail.json.jbuilder b/app/views/project_trends/_detail.json.jbuilder index 04de10f6a..f8d1006dd 100644 --- a/app/views/project_trends/_detail.json.jbuilder +++ b/app/views/project_trends/_detail.json.jbuilder @@ -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) diff --git a/app/views/project_trends/last.json.jbuilder b/app/views/project_trends/last.json.jbuilder new file mode 100644 index 000000000..04edf97a9 --- /dev/null +++ b/app/views/project_trends/last.json.jbuilder @@ -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 + diff --git a/app/views/user_rank/_detail.json.jbuilder b/app/views/user_rank/_detail.json.jbuilder index 7632c408b..e3f8ce5d0 100644 --- a/app/views/user_rank/_detail.json.jbuilder +++ b/app/views/user_rank/_detail.json.jbuilder @@ -18,4 +18,34 @@ else json.identifier popular_project_common["identifier"] json.description popular_project_common["description"] end -end \ No newline at end of file +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 \ No newline at end of file diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index e7c586417..d5c68d448 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -1,240 +1,241 @@ -zh-CN: - error: - record_not_found: 您访问的页面不存在或已被删除 - forbidden: 您没有权限进行该操作 - unauthorized: 未登录 - - button_test: 测试 - button_edit: 编辑 - button_delete: 删除 - - admins_apply_status: - status: - 'pending': '待审批' - 'processed': '已审批' - 'refused': '已拒绝' - 'agreed': '已同意' - trend: - Issue: 疑修(Issue) - PullRequest: 合并请求(PR) - VersionRelease: 版本发布 - create: 创建了 - journal: 回复了 - close: 关闭了 - merge: 合并了 - push: 发布了 - - version: - draft: 草稿 - - journal_detail: - branch_name: 分支 - close_pr: 合并 - merge: 合并 - issue_tags_value: 标记 - lock_issue: 锁定工单 - unlock_issue: 解锁工单 - destroy_issue_depend: 删除依赖 - issue_depend: 增加依赖 - work_time: 开始工作 - cancel_time: 取消时间跟踪 - end_time: 停止工作 - subject: 主题 - description: 描述 - is_private: 私有 - assigned_to_id: 指派给 - tracker_id: 类型 - status_id: 状态 - priority_id: 优先级 - fixed_version_id: 里程碑 - start_date: 开始日期 - due_date: 结束日期 - estimated_hours: 添加耗时 - done_ratio: 完成度 - t: 是 - f: 否 - true: 是 - false: 否 - issue_tag_ids: 标记 - issue_type: 分类 - token: 悬赏金额 - close_issue: 工单 - activerecord: - attributes: - organization: - login: '组织名称' - user: - login: '登录名' - lastname: '姓名' - nickname: '昵称' - discuss: - content: '内容' - journals_for_message: - notes: '内容' - subject: - name: '课程名称' - description: '课程简介' - learning_notes: '学习须知' - stage: - name: '章节名称' - description: '章节描述' - shixun_info: - description: '简介' - fork_reason: 'fork原因' - challenge: - task_pass: '过关任务' - test_set: - input: '输入' - output: '输出' - challenge_question: - option_name: '选项' - challenge_choose: - subject: '题干' - challenge_answer: - contents: '答案内容' - memo: - content: '帖子内容' - course: - name: '课堂名称' - course_group: - name: '分班名称' - course_module: - module_name: '目录名称' - course_second_category: - name: '目录名称' - inform: - name: '标题' - description: '内容' - course_stage: - name: '章节名称' - description: '章节描述' - attachment: - description: '资源描述' - message: - subject: '标题' - message_detail: - content: '内容' - homework_common: - name: '标题' - description: '内容' - explanation: '内容' - reference_answer: '参考答案' - student_work: - description: '内容' - student_works_score: - comment: '评语' - challenge_work_score: - comment: '评语' - shixun_work_comment: - comment: '评语' - hidden_comment: '隐藏评语' - graduation_topic: - name: '选题名称' - description: '选题简介' - graduation_task: - name: '任务标题' - description: '内容' - graduation_work: - description: '作品内容' - graduation_work_score: - comment: '评语' - poll: - polls_name: '问卷标题' - polls_description: '问卷须知' - poll_question: - question_title: '题干' - poll_answer: - answer_text: '选项' - poll_vote: - vote_text: '内容' - exercise: - exercise_name: '试卷标题' - exercise_description: '试卷须知' - exercise_question: - question_title: '题干' - exercise_choice: - choice_text: '选项' - exercise_answer: - answer_text: '答案' - exercise_standard_answer: - answer_text: '参考答案' - exercise_answer_comment: - comment: '评语' - homework_bank: - name: '标题' - description: '内容' - reference_answer: '参考答案' - gtask_bank: - name: '任务标题' - description: '内容' - gtopic_bank: - name: '选题名称' - description: '选题简介' - exercise_bank: - name: '试卷标题' - description: '试卷须知' - exercise_bank_question: - question_title: '题干' - exerise_bank_choice: - choice_text: '选项' - exercise_bank_standard_answer: - answer_text: '参考答案' - library: - title: '标题' - content: '内容' - author_name: '作者姓名' - author_school_name: '作者单位名称' - competition: - introduction: '简介' - competition_module_md_content: - content: '内容' - chart_rule: - content: '内容' - project_package: - title: '标题' - examination_bank: - name: '试卷名称' - item_bank: - name: '题干' - item_analysis: - analysis: '解析' - item_choice: - choice_text: '选项' - hack: - name: '任务名称' - description: '描述' - hack_set: - input: '测试集输入' - output: '测试集输出' - hack_user_lastest_code: - notes: '笔记' - trustie_hack: - description: '描述' - discipline: - name: '名称' - sub_discipline: - name: '名称' - tag_discipline: - name: '名称' - live_link: - description: '说明' - url: '链接' - course_name: '课程名称' - platform: '直播平台' - live_time: '开播时间' - duration: '直播时长' - project_language: - name: '项目语言' - license: - name: '许可证名称' - content: '许可证内容' - ignore: - name: 'git忽略文件名称' - content: 'git忽略文件内容' - feedback_message_history: - title: '' - close_pr: 合并请求 - roles: - Developer: 开发者 - Reporter: 报告者 +zh-CN: + error: + record_not_found: 您访问的页面不存在或已被删除 + forbidden: 您没有权限进行该操作 + unauthorized: 未登录 + + button_test: 测试 + button_edit: 编辑 + button_delete: 删除 + + admins_apply_status: + status: + 'pending': '待审批' + 'processed': '已审批' + 'refused': '已拒绝' + 'agreed': '已同意' + trend: + Issue: 疑修(Issue) + PullRequest: 合并请求(PR) + VersionRelease: 版本发布 + CommitLog: 代码(Commit) + create: 创建了 + journal: 回复了 + close: 关闭了 + merge: 合并了 + push: 发布了 + + version: + draft: 草稿 + + journal_detail: + branch_name: 分支 + close_pr: 合并 + merge: 合并 + issue_tags_value: 标记 + lock_issue: 锁定工单 + unlock_issue: 解锁工单 + destroy_issue_depend: 删除依赖 + issue_depend: 增加依赖 + work_time: 开始工作 + cancel_time: 取消时间跟踪 + end_time: 停止工作 + subject: 主题 + description: 描述 + is_private: 私有 + assigned_to_id: 指派给 + tracker_id: 类型 + status_id: 状态 + priority_id: 优先级 + fixed_version_id: 里程碑 + start_date: 开始日期 + due_date: 结束日期 + estimated_hours: 添加耗时 + done_ratio: 完成度 + t: 是 + f: 否 + true: 是 + false: 否 + issue_tag_ids: 标记 + issue_type: 分类 + token: 悬赏金额 + close_issue: 工单 + activerecord: + attributes: + organization: + login: '组织名称' + user: + login: '登录名' + lastname: '姓名' + nickname: '昵称' + discuss: + content: '内容' + journals_for_message: + notes: '内容' + subject: + name: '课程名称' + description: '课程简介' + learning_notes: '学习须知' + stage: + name: '章节名称' + description: '章节描述' + shixun_info: + description: '简介' + fork_reason: 'fork原因' + challenge: + task_pass: '过关任务' + test_set: + input: '输入' + output: '输出' + challenge_question: + option_name: '选项' + challenge_choose: + subject: '题干' + challenge_answer: + contents: '答案内容' + memo: + content: '帖子内容' + course: + name: '课堂名称' + course_group: + name: '分班名称' + course_module: + module_name: '目录名称' + course_second_category: + name: '目录名称' + inform: + name: '标题' + description: '内容' + course_stage: + name: '章节名称' + description: '章节描述' + attachment: + description: '资源描述' + message: + subject: '标题' + message_detail: + content: '内容' + homework_common: + name: '标题' + description: '内容' + explanation: '内容' + reference_answer: '参考答案' + student_work: + description: '内容' + student_works_score: + comment: '评语' + challenge_work_score: + comment: '评语' + shixun_work_comment: + comment: '评语' + hidden_comment: '隐藏评语' + graduation_topic: + name: '选题名称' + description: '选题简介' + graduation_task: + name: '任务标题' + description: '内容' + graduation_work: + description: '作品内容' + graduation_work_score: + comment: '评语' + poll: + polls_name: '问卷标题' + polls_description: '问卷须知' + poll_question: + question_title: '题干' + poll_answer: + answer_text: '选项' + poll_vote: + vote_text: '内容' + exercise: + exercise_name: '试卷标题' + exercise_description: '试卷须知' + exercise_question: + question_title: '题干' + exercise_choice: + choice_text: '选项' + exercise_answer: + answer_text: '答案' + exercise_standard_answer: + answer_text: '参考答案' + exercise_answer_comment: + comment: '评语' + homework_bank: + name: '标题' + description: '内容' + reference_answer: '参考答案' + gtask_bank: + name: '任务标题' + description: '内容' + gtopic_bank: + name: '选题名称' + description: '选题简介' + exercise_bank: + name: '试卷标题' + description: '试卷须知' + exercise_bank_question: + question_title: '题干' + exerise_bank_choice: + choice_text: '选项' + exercise_bank_standard_answer: + answer_text: '参考答案' + library: + title: '标题' + content: '内容' + author_name: '作者姓名' + author_school_name: '作者单位名称' + competition: + introduction: '简介' + competition_module_md_content: + content: '内容' + chart_rule: + content: '内容' + project_package: + title: '标题' + examination_bank: + name: '试卷名称' + item_bank: + name: '题干' + item_analysis: + analysis: '解析' + item_choice: + choice_text: '选项' + hack: + name: '任务名称' + description: '描述' + hack_set: + input: '测试集输入' + output: '测试集输出' + hack_user_lastest_code: + notes: '笔记' + trustie_hack: + description: '描述' + discipline: + name: '名称' + sub_discipline: + name: '名称' + tag_discipline: + name: '名称' + live_link: + description: '说明' + url: '链接' + course_name: '课程名称' + platform: '直播平台' + live_time: '开播时间' + duration: '直播时长' + project_language: + name: '项目语言' + license: + name: '许可证名称' + content: '许可证内容' + ignore: + name: 'git忽略文件名称' + content: 'git忽略文件内容' + feedback_message_history: + title: '' + close_pr: 合并请求 + roles: + Developer: 开发者 + Reporter: 报告者 Manager: 管理员 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8b943f543..0e760fbe9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20230417032154_update_commit_log_utf8.rb b/db/migrate/20230417032154_update_commit_log_utf8.rb new file mode 100644 index 000000000..fa8ac44d7 --- /dev/null +++ b/db/migrate/20230417032154_update_commit_log_utf8.rb @@ -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