diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ac99c30f5..157d5e7f1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -680,6 +680,14 @@ class ApplicationController < ActionController::Base relation.page(page).per(limit) end + def kaminari_unlimit_paginate(relation) + limit = params[:limit] || params[:per_page] + limit = (limit.to_i.zero? || limit.to_i > 9999) ? 9999 : limit.to_i + page = params[:page].to_i.zero? ? 1 : params[:page].to_i + + relation.page(page).per(limit) + end + def kaminari_array_paginate(relation) limit = params[:limit] || params[:per_page] limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d7fdb51ac..1d98b17f4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -169,18 +169,12 @@ class RepositoriesController < ApplicationController end def contributors - @cache_result = $redis_cache.get("ProjectSpecialCommit:#{@project.id}") - if @cache_result.present? - @total_count = Project.mindspore_contributors.size - @contributors = kaminari_array_paginate(Project.mindspore_contributors) - else - if params[:filepath].present? || @project.educoder? - @contributors = [] - else - result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) - @total_count = result[:total_count] - @contributors = result.is_a?(Hash) ? result[:body] : [] - end + if params[:filepath].present? || @project.educoder? + @contributors = [] + else + result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]}) + @total_count = result[:total_count] + @contributors = result.is_a?(Hash) ? result[:body] : [] end rescue @contributors = [] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 35f44b4e2..6cf505a6d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -406,7 +406,7 @@ class UsersController < ApplicationController is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id) scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user) @total_count = scope.size - @projects = paginate(scope) + @projects = kaminari_unlimit_paginate(scope) end diff --git a/app/models/concerns/watchable.rb b/app/models/concerns/watchable.rb index 3ca9f04e3..a8a19a40a 100644 --- a/app/models/concerns/watchable.rb +++ b/app/models/concerns/watchable.rb @@ -31,7 +31,7 @@ module Watchable following.size end - def mindspore_contribution_perc(project) + def simple_contribution_perc(project) @project = project @user = self @@ -39,15 +39,19 @@ module Watchable (count_user * 1.0 / (count_all + 0.000000001)).round(5) end - if @project['use_blockchain'] == true or @project['use_blockchain'] == 1 + if (@project['use_blockchain'] == true or @project['use_blockchain'] == 1) && @user.id.present? balance_user = Blockchain::BalanceQueryOneProject.call({"user_id": @user.id, "project_id": @project.id}) balance_all = Blockchain::RepoBasicInfo.call({"project_id": @project.id})["cur_supply"] score = cal_perc(balance_user, balance_all) else - commits_all = Project.mindspore_contributors.map{|i| i['contributions']}.sum - commit_user = Project.mindspore_contributors.select{|i| i['login'] == @user.login}.map{|i| i['contributions']}.sum - score = cal_perc(commit_user, commits_all) + contributors = [] + result = Gitea::Repository::Contributors::GetService.call(@project.owner, @project.identifier,{q_name: @user.login, q_email: @user.mail}) + user_contribution = result[:body][0] + commits_all = result[:total_contributions] + score = cal_perc(user_contribution["contributions"], commits_all) end + + (score * 100).round(1).to_s + "%" end def contribution_perc(project) diff --git a/app/models/fork_user.rb b/app/models/fork_user.rb index 2d74af4a4..92040ad13 100644 --- a/app/models/fork_user.rb +++ b/app/models/fork_user.rb @@ -25,10 +25,12 @@ class ForkUser < ApplicationRecord def incre_project_common CacheAsyncSetJob.perform_later("project_common_service", {forks: 1}, self.project_id) + self.project.update_column(:updated_on, Time.now) end def decre_project_common CacheAsyncSetJob.perform_later("project_common_service", {forks: -1}, self.project_id) + self.project.update_column(:updated_on, Time.now) end def incre_user_statistic diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 5d4ae0d80..0250f012e 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -26,10 +26,12 @@ class PraiseTread < ApplicationRecord def incre_project_common CacheAsyncSetJob.perform_later("project_common_service", {praises: 1}, self.praise_tread_object_id) if self.praise_tread_object_type == "Project" + self.praise_tread_object.update_column(:updated_on, Time.now) if self.praise_tread_object_type == "Project" end def decre_project_common CacheAsyncSetJob.perform_later("project_common_service", {praises: -1}, self.praise_tread_object_id) if self.praise_tread_object_type == "Project" + self.praise_tread_object.update_column(:updated_on, Time.now) if self.praise_tread_object_type == "Project" end def incre_user_statistic diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 5a2cd96fb..f9d646ca9 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -28,10 +28,12 @@ class Watcher < ApplicationRecord def incre_project_common CacheAsyncSetJob.perform_later("project_common_service", {watchers: 1}, self.watchable_id) if self.watchable_type == "Project" + self.watchable.update_column(:updated_on, Time.now) if self.watchable_type == "Project" end def decre_project_common CacheAsyncSetJob.perform_later("project_common_service", {watchers: -1}, self.watchable_id) if self.watchable_type == "Project" + self.watchable.update_column(:updated_on, Time.now) if self.watchable_type == "Project" end def incre_user_statistic diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 31c17846a..9cb43f0a0 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -34,6 +34,10 @@ class Projects::ListMyQuery < ApplicationQuery elsif params[:category].to_s == "forked" #我fork的 fork_ids = user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id) projects = projects.where(id: fork_ids) + elsif params[:category].to_s == "admin" + normal_projects = projects.joins(members: :roles).where(members: {user_id: user.id}, roles: {name: %w(Manager)}).to_sql + org_projects = projects.joins(team_projects: [team: :team_users]).where(teams: {authorize: "owner"},team_users: {user_id: user.id}).to_sql + projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct # elsif params[:category].to_s == "public" # projects = projects.visible.joins(:members).where(members: { user_id: user.id }) # elsif params[:category].to_s == "private" diff --git a/app/services/api/v1/issues/list_service.rb b/app/services/api/v1/issues/list_service.rb index e5eff6c48..4fbc4599f 100644 --- a/app/services/api/v1/issues/list_service.rb +++ b/app/services/api/v1/issues/list_service.rb @@ -69,7 +69,7 @@ class Api::V1::Issues::ListService < ApplicationService issues = issues.joins(:assigners).where(users: {id: assigner_id}) if assigner_id.present? # status_id - issues = issues.where(status_id: status_id) if status_id.present? + issues = issues.where(status_id: status_id) if status_id.present? && category != 'closed' if begin_date&.present? || end_date&.present? issues = issues.where("issues.created_on between ? and ?", begin_date&.present? ? begin_date.to_time : Time.now.beginning_of_day, end_date&.present? ? end_date.to_time.end_of_day : Time.now.end_of_day) diff --git a/app/services/gitea/repository/contributors/get_service.rb b/app/services/gitea/repository/contributors/get_service.rb index ea121a50d..cfc2e9340 100644 --- a/app/services/gitea/repository/contributors/get_service.rb +++ b/app/services/gitea/repository/contributors/get_service.rb @@ -1,11 +1,13 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService - attr_reader :owner, :repo_name, :page, :limit + attr_reader :owner, :repo_name, :page, :limit, :q_name, :q_email def initialize(owner, repo_name, params) @owner = owner @repo_name = repo_name @page = params[:page] || 1 @limit = params[:limit] || 20 + @q_name = params[:q_name] || "" + @q_email = params[:q_email] || "" end def call @@ -15,7 +17,7 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService private def params - Hash.new.merge(token: owner.gitea_token, page: page, limit: limit) + Hash.new.merge(token: owner.gitea_token, page: page, limit: limit, q_name: q_name, q_email: q_email) end def url @@ -29,7 +31,8 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService headers = response.headers.to_hash body = JSON.parse(response.body) total_count = headers["x-total"] - result.merge(total_count: total_count.to_i, body: body) + total_contributions = headers["x-total-contributions"] + result.merge(total_count: total_count.to_i, total_contributions: total_contributions.to_i, body: body) else nil # {status: -1, message: "#{body['message']}"} diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index 8b4bb6af3..4a5a433be 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -8,6 +8,7 @@ end json.status_name issue.issue_status&.name json.priority_name issue.priority&.name json.milestone_name issue.version&.name +json.milestone_id issue.fixed_version_id json.author do if issue.user.present? json.partial! "api/v1/users/simple_user", locals: {user: issue.user} diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index dca0a93bf..e93bdf370 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -2,16 +2,11 @@ user = $redis_cache.hgetall("v2-owner-common:#{contributor["login"]}-#{contribut if user.blank? json.contributions contributor["contributions"] # json.gid contributor["id"] - json.login contributor["login"] + json.login contributor["login"].downcase json.type nil - json.name contributor["login"] + json.name contributor["login"].downcase json.image_url User::Avatar.get_letter_avatar_url(contributor["login"]) - if @cache_result.present? - db_user = User.find_by_id(contributor["id"]) - if db_user.present? - json.contribution_perc db_user.contribution_perc(project) - end - end + json.contribution_perc User.new(login: contributor["login"], mail: contributor["email"]).simple_contribution_perc(project) else json.contributions contributor["contributions"] # json.gid contributor["id"] @@ -21,6 +16,6 @@ else json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) if db_user.present? - json.contribution_perc db_user.contribution_perc(project) + json.contribution_perc db_user.simple_contribution_perc(project) end end