From 0aee41c7eaea3f86555f5bc94b2e941db6f7496b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Apr 2023 20:27:18 +0800 Subject: [PATCH] =?UTF-8?q?commit=E6=8F=90=E5=8F=96=E8=B4=A1=E7=8C=AE?= =?UTF-8?q?=E8=80=85=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/batch_add_contributors.rake | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/tasks/batch_add_contributors.rake b/lib/tasks/batch_add_contributors.rake index 1e9e5c57a..633ee869e 100644 --- a/lib/tasks/batch_add_contributors.rake +++ b/lib/tasks/batch_add_contributors.rake @@ -40,15 +40,19 @@ namespace :batch_add_contributors do # user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction - if Issue.find_by_sql("select id from commit_contributors where name='#{commiter['email']}'").present? - sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" + site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") + if site.present? + puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" + if commit_date.to_i < site.created_at.to_i + sql = "update commit_contributors set created_at ='#{commit_date_str}' where name='#{commiter['email']}'" + end else sql = "INSERT INTO commit_contributors (`created_at`, `count`, `name`) VALUES ('#{commit_date_str}',1,'#{commiter['email']}')" end puts "sql====#{sql}" + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction sql_connection.execute(sql) sql_connection.commit_db_transaction @@ -90,10 +94,8 @@ namespace :batch_add_contributors do # user_id = user&.id || project.user_id commit_date = Time.parse(commit['commit']['author']['date']) commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") - - sql_connection = ActiveRecord::Base.connection - sql_connection.begin_db_transaction site = Site.find_by_sql("select id, created_at from commit_contributors where name='#{commiter['email']}'") + if site.present? puts "commit_date====#{commit_date},created_at======#{site.first&.created_at}" if commit_date.to_i < site.created_at.to_i @@ -104,6 +106,8 @@ namespace :batch_add_contributors do end puts "sql====#{sql}" + sql_connection = ActiveRecord::Base.connection + sql_connection.begin_db_transaction sql_connection.execute(sql) sql_connection.commit_db_transaction