diff --git a/README.md b/README.md index 46e79e556..4181dd66c 100644 --- a/README.md +++ b/README.md @@ -1281,6 +1281,8 @@ http://localhost:3000/api/18816895620/mirror_demo | jq |watchers_count |int|关注数量| |branches_count |int|分支数量| |commits_count |int|总提交记录数量| +|issues_count |int|总提交记录数量| +|pull_requests_count |int|总提交记录数量| |praised |boolean|当前登录用户是否已点赞,true:已点赞,fasle:未点赞, 用户未登录状态为null| |watched |boolean|当前登录用户是否已关注,true:已关注,fasle:未关注, 用户未登录状态为null| |permission |string|当前登录用户对该仓库的操作权限, Manager:管理员,可以在线编辑文件、在线新建文件、可以设置仓库的基本信息; Developer:开发人员,可在线编辑文件、在线新建文件、不能设置仓库信息; Reporter: 报告人员,只能查看信息,不能设置仓库信息、不能在线编辑文件、不能在线新建文件;用户未登录时也会返回Reporter, 说明也只有读取文件的权限 | @@ -1308,6 +1310,8 @@ http://localhost:3000/api/18816895620/mirror_demo | jq "watchers_count": 1, "branches_count": 6, "commits_count": 107, + "issues_count": 0, + "pull_requests_count": 0, "permission": "Manager", "mirror_url": "https://gitea.com/CasperVector/slew.git", "watched": true, diff --git a/app/models/issue.rb b/app/models/issue.rb index b63f27bd6..4d9f5ebb2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1,6 +1,6 @@ class Issue < ApplicationRecord #issue_type 1为普通,2为悬赏 - belongs_to :project + belongs_to :project, :counter_cache => true belongs_to :tracker,optional: true has_many :project_trends, as: :trend, dependent: :destroy has_one :pull_request @@ -87,4 +87,4 @@ class Issue < ApplicationRecord journals.where.not(notes: [nil, ""]).journal_includes.limit(2) end -end \ No newline at end of file +end diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 0e94b68b8..1c41f6a46 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -2,8 +2,8 @@ class PullRequest < ApplicationRecord #status 0 默认未合并, 1表示合并, 2表示请求拒绝 belongs_to :issue belongs_to :user - belongs_to :project + belongs_to :project, :counter_cache => true has_many :pull_request_assigns, foreign_key: :pull_request_id has_many :pull_request_tags, foreign_key: :pull_request_id has_many :project_trends, as: :trend, dependent: :destroy -end \ No newline at end of file +end diff --git a/db/migrate/20200213090203_add_issues_count_and_pull_requests_count_to_projects.rb b/db/migrate/20200213090203_add_issues_count_and_pull_requests_count_to_projects.rb new file mode 100644 index 000000000..a7beb6678 --- /dev/null +++ b/db/migrate/20200213090203_add_issues_count_and_pull_requests_count_to_projects.rb @@ -0,0 +1,6 @@ +class AddIssuesCountAndPullRequestsCountToProjects < ActiveRecord::Migration[5.2] + def change + add_column :projects, :issues_count, :integer, :default => 0 + add_column :projects, :pull_requests_count, :integer, :default => 0 + end +end