diff --git a/app/controllers/mark_files_controller.rb b/app/controllers/mark_files_controller.rb index 88856c35a..53bd279e7 100644 --- a/app/controllers/mark_files_controller.rb +++ b/app/controllers/mark_files_controller.rb @@ -5,16 +5,17 @@ class MarkFilesController < ApplicationController def index @files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token) - - MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker| - @files_result['Files'].echo do |file| - worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name']) - end - end @mark_files = MarkFile.where(pull_request_id: @pull_request.id) end def create + unless @pull_request.mark_files.present? + MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker| + @files_result['Files'].each do |file| + worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name']) + end + end + end end private diff --git a/app/views/mark_files/index.json.jbuilder b/app/views/mark_files/index.json.jbuilder index 18bf90b5d..ae422c91f 100644 --- a/app/views/mark_files/index.json.jbuilder +++ b/app/views/mark_files/index.json.jbuilder @@ -1,12 +1,13 @@ json.status 0 json.message 'success' -json.count @mark_files.count +json.count @files_result['NumFiles'] json.files do - json.array! @mark_files do |file| - json.sha file.file_path_sha - json.name file.file_path - json.mark_as_read file.mark_as_read - json.updated_after_read file.updated_after_read + json.array! @files_result do |file| + mark_file = @mark_files.select{|mark| mark.file_path.to_s == file['Name']}.first + json.sha Base64.encode64(file.file['Name'].to_s) + json.name file.file['Name'] + json.mark_as_read mark_file.present? ? mark_file.mark_as_read : false + # json.updated_after_read mark_file.present? ? mark_file.updated_after_read : false end end