add: compare add paginate

This commit is contained in:
yystopf 2022-04-28 18:54:56 +08:00
commit d799d329ff
3 changed files with 14 additions and 3 deletions

View File

@ -9,6 +9,10 @@ class CompareController < ApplicationController
load_compare_params
compare
@merge_status, @merge_message = get_merge_message
@page_size = page_size <= 0 ? 1 : page_size
@page_limit = page_limit <=0 ? 15 : page_limit
@page_offset = (@page_size -1) * @page_limit
Rails.logger.info("+========#{@page_size}-#{@page_limit}-#{@page_offset}")
end
private
@ -53,4 +57,12 @@ class CompareController < ApplicationController
def gitea_compare(base, head)
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), current_user.gitea_token)
end
def page_size
params.fetch(:page, 1).to_i
end
def page_limit
params.fetch(:limit, 15).to_i
end
end

View File

@ -36,7 +36,6 @@ module RepositoriesHelper
end
def render_cache_commit_author(author_json)
Rails.logger.info author_json['Email']
if author_json["name"].present? && author_json["email"].present?
return find_user_in_redis_cache(author_json['name'], author_json['email'])
end

View File

@ -1,7 +1,7 @@
json.commits_count @compare_result['Commits']&.size
json.commits_count @compare_result['CommitsCount']
# json.commits @compare_result['Commits'], partial: 'pull_requests/commit', as: :commit
json.commits do
json.array! @compare_result['Commits'] do |commit|
json.array! @compare_result['Commits'][@page_offset...(@page_offset + @page_limit)] do |commit|
json.author do
json.partial! 'repositories/commit_author', locals: { user: render_cache_commit_author(commit['Committer']), name: commit['Committer']['Name'] }
end