Skip to content

Ancestry with ActiveImport #433

@Brotakuu

Description

@Brotakuu

I'm using active import to import comment trees. Is there any way to create the ancestry tree during the import (when the primary key id is not created yet)?

Currently, I'm importing all the comments, then looping through each comment to add the parent, and it is very slow even with indexes:

comments_to_import = []
import_data.each do |comment|
    comments_to_import << Comment.new(is_parent: comment.parent_uuid.nil?, uuid: comment.uuid, parent_uuid: comment.parent_uuid, body: comment.body)
end
Comment.import comments_to_import

# build comment tree
Comment.where(is_parent: false, ancestry: nil).all.each do |c|
    parent = Comment.find_by(uuid: c.parent_uuid)
    c.update(parent: parent)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions