diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bcbe031b6..550716eaa 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -56,6 +56,7 @@ class ProjectsController < ApplicationController Projects::CreateForm.new(project_params).validate! @project = Projects::CreateService.new(current_user, project_params).call OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id) + UpdateProjectTopicJob.set(wait: 5.seconds).perform_later(@project.id) if @project.id.present? end rescue Exception => e uid_logger_error(e.message) diff --git a/app/jobs/migrate_remote_repository_job.rb b/app/jobs/migrate_remote_repository_job.rb index 696607ae3..428f9a726 100644 --- a/app/jobs/migrate_remote_repository_job.rb +++ b/app/jobs/migrate_remote_repository_job.rb @@ -16,6 +16,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob project_id = repo&.project&.id puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############" OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present? + UpdateProjectTopicJob.set(wait: 5.seconds).perform_later(project_id) if project_id.present? puts "############ mirror status: #{repo.mirror.status} ############" else repo&.mirror&.failed! diff --git a/app/jobs/update_project_topic_job.rb b/app/jobs/update_project_topic_job.rb new file mode 100644 index 000000000..dfa485ff5 --- /dev/null +++ b/app/jobs/update_project_topic_job.rb @@ -0,0 +1,32 @@ +class UpdateProjectTopicJob < ApplicationJob + include ProjectsHelper + + queue_as :message + + def perform(project_id) + project = Project.find_by(id: project_id) + return if project.blank? + begin + languages = $gitea_client.get_repos_languages_by_owner_repo(project.owner.login, project.identifier) + topic_count = 0 + if project.project_category_id.present? + project_topic = ProjectTopic.find_or_create_by!(name: project.project_category.name.downcase) + project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: project.id) + if project_topic.present? && project_topic_ralate.present? + topic_count +=1 + end + end + languages.each do |k, _| + next if topic_count >= 3 + project_topic = ProjectTopic.find_or_create_by!(name: k.downcase) + project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: project.id) + if project_topic.present? && project_topic_ralate.present? + topic_count +=1 + end + end + rescue + + end + end + +end \ No newline at end of file diff --git a/lib/tasks/init_project_topic.rake b/lib/tasks/init_project_topic.rake index f6fcd4b96..5255a4aa2 100644 --- a/lib/tasks/init_project_topic.rake +++ b/lib/tasks/init_project_topic.rake @@ -4,7 +4,7 @@ namespace :init_project_topic do desc "Init Project Topic for Project" task project: :environment do - Project.order(created_at: :desc).find_each do |p| + Project.where(platform: 'forge').order(created_at: :desc).find_each do |p| next unless p.owner.present? next if p.project_topics.size >= 3 begin