修复:group by sync repository

This commit is contained in:
yystopf 2024-04-25 15:14:00 +08:00
parent 31ede9c69d
commit ae4ad29821
2 changed files with 2 additions and 2 deletions

View File

@ -97,7 +97,7 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present?
@sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: params[:sync_repository_ids].split(","))
@sync_repository_branches = @sync_repository_branches.ransack(gitlink_branch_name_or_external_branch_name_cont: params[:branch_name]).result if params[:branch_name].present?
@group_sync_repository_branch = @sync_repository_branches.group(:sync_repository_id, :gitlink_branch_name, :external_branch_name).select("max(updated_at) as updated_at, sync_repository_id, gitlink_branch_name, external_branch_name").sort_by{|i|i.updated_at}
@group_sync_repository_branch = @sync_repository_branches.joins(:sync_repository).group("sync_repositories.type, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").select("sync_repositories.type as type,max(sync_repository_branches.updated_at) as updated_at, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").sort_by{|i|i.updated_at}
end
def history

View File

@ -2,7 +2,7 @@ json.total_count @group_sync_repository_branch.count
json.sync_repository_branches @group_sync_repository_branch.each do |item|
json.gitlink_branch_name item.gitlink_branch_name
json.external_branch_name item.external_branch_name
branches = @sync_repository_branches.where(gitlink_branch_name: item.gitlink_branch_name, external_branch_name: item.external_branch_name).order(updated_at: :desc)
branches = @sync_repository_branches.joins(:sync_repository).where(sync_repositories: {type: item.type}, gitlink_branch_name: item.gitlink_branch_name, external_branch_name: item.external_branch_name).order(updated_at: :desc)
branch = branches.first
json.type branch&.sync_repository&.type
json.sync_time branch.sync_time.present? ? branch.sync_time.strftime("%Y-%m-%d %H:%M:%S") : nil