From 03a53f56fd5904f6e64f140f5f65ea01b4db9ae8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 18 Apr 2023 16:56:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E5=9B=BEcommit=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/commit_log_to_db.rake | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/tasks/commit_log_to_db.rake b/lib/tasks/commit_log_to_db.rake index 2f29bee8f..cfde9bd05 100644 --- a/lib/tasks/commit_log_to_db.rake +++ b/lib/tasks/commit_log_to_db.rake @@ -38,10 +38,12 @@ namespace :commit_log_to_db do data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction - sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" - sql_connection.execute(sql) + if data.present? + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + sql_connection.execute(sql) + end end end @@ -74,10 +76,12 @@ namespace :commit_log_to_db do data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}')," end data = data[0,data.length-1] - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction - sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" - sql_connection.execute(sql) + if data.present? + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction + sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}" + sql_connection.execute(sql) + end end end \ No newline at end of file