Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How make bulk insert and create the tree whitout use rebuild! #398

Closed
rocket4ce opened this issue Feb 20, 2019 · 3 comments
Closed

How make bulk insert and create the tree whitout use rebuild! #398

rocket4ce opened this issue Feb 20, 2019 · 3 comments
Labels

Comments

@rocket4ce
Copy link

I'm refactor my code with bulk_insert for a tree (i'm already using awesome_nested_set) and I have an array with several objects, where they only have the parent_id.

Actually i'm using rebuild inside a Job. But I think that is not an efficient solution. So, I appreciate if you have any ideas to improve my code.

I use bulk_insert gem.

Job

class MassiveInsertJob < ApplicationJob
  queue_as :default

  def perform (task, structure)
    Task.create_rhytmic_task(task, structure)
    Task.rebuild!
    begin
      SendPusherJob.perform_later(task, structure, {message: 'Rhythmic task ok', type: 'notice'})
    rescue => error
      puts error
    end
  end
end

Bulk

Task.bulk_insert(:name, :unique_id, :owner_id, :sector_id, :current_progress,
                    :base_start_date, :base_end_date, :base_duration,
                    :base_days_duration, :start_date, :end_date, :duration,
                    :days_duration, :current_state, :completion_status,
                    :reschedules_count, :source, :project_gantt_id, :rhytmic_task,
                    :active, :calendar_unique_id, :parent_id, :lft, :rgt,
                    :created_at, :updated_at)  do |worker|
     array_children.each do |task|
       array = [task[:name], task[:unique_id], task[:owner_id], task[:sector_id],
                task[:current_progress], task[:base_start_date],
                task[:base_end_date], task[:base_duration], task[:base_days_duration],
                task[:start_date], task[:end_date], task[:duration],
                task[:days_duration], task[:current_state],
                task[:completion_status], task[:reschedules_count],
                task[:source], task[:project_gantt_id], task[:rhytmic_task],
                task[:active], task[:calendar_unique_id],
                task[:parent_id], task[:lft], task[:rgt], DateTime.now, DateTime.now]
       worker.add array
     end
   end
@rocket4ce rocket4ce changed the title How make bulk insert and create the tree whit a new scope? How make bulk insert and create the tree whitout use rebuild! Feb 20, 2019
@acolchagoff
Copy link

is it possible to use scope and rebuild a single scope?

@drewB
Copy link

drewB commented Oct 2, 2019

You can see how we handled this in #326 (comment)

@stale
Copy link

stale bot commented Jan 10, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 10, 2021
@stale stale bot closed this as completed Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants