evilmartians / evil-seed

A Gem for creating partial anonymized dumps of your database using your app model relations.
MIT License
450 stars 19 forks source link

Recursive execution? #21

Open davidw opened 11 months ago

davidw commented 11 months ago
    def dump_belongs_to_associations!
      belongs_to_reflections.map do |reflection|
        next if to_load_map[reflection.name].empty?
        RelationDumper.new(
          build_relation(reflection),
          root_dumper,
          "#{association_path}.#{reflection.name}",
          search_key:       reflection.association_primary_key,
          identifiers:      to_load_map[reflection.name],
          limitable:        false,
        ).call
      end
    end

From RelationDumper - to me it seems like this is recursive, which might cause some resource issues in a larger DB with a lot of relationships.

Envek commented 11 months ago

AFAIR I made it to be able to dump tree-like structures stored in HABTM. So you can choose parent records and get all their descendants.

davidw commented 11 months ago

@Envek right, but it might make sense to put things into a queue and then run that...? It's holding open a lot of resources, I think, when it goes into deeply nested stuff.

davidw commented 11 months ago

Maybe there's something else going on... it seems to keep picking up the same models via various associations. I'm dumping the associaton path and get stuff like

xxxxxxxxxxxxxxxxxxxxxx.yyyyyyyyyyyyyyyyyyyyyy_custom_elements.yyyyyyyyyyyyyyyyyyyyyy.agents.user.yyyyyyyyyyyyyyyyyyyyyy.agents.office_memberships.office.aaaaaaaaaaaaaaaaaas.zzzzzzzzzzzzzzzzzzzzzz.neighborhood.geography_similarities.similar_geography.geography_similarities.similar_geography.geography_similarities.similar_geography.geography_similarities.similar_geography.geography_similarities.similar_geography.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.notes.user.yyyyyyyyyyyyyyyyyyyyyy.agents.user.yyyyyyyyyyyyyyyyyyyyyy.agents.user.yyyyyyyyyyyyyyyyyyyyyy.client_website.yyyyyyyyyyyyyyyyyyyyyy.agents.user.search_states.visual_report.user.yyyyyyyyyyyyyyyyyyyyyy.client_website.client_website_employees.clientwebsiteemployees_agents.agent.user.search_states.shareables.recipient.notifications.sender.search_states.shareables.recipient.received_shareables.bbbbbbbbbbbbbbbb_client.list.bbbbbbbbbbbbbbbb_clients.client.search_states.shareables.recipient.notifications.sender.yyyyyyyyyyyyyyyyyyyyyy.agents.user.yyyyyyyyyyyyyyyyyyyyyy.agents.user.search_states.shareables.recipient.notifications.sender.yyyyyyyyyyyyyyyyyyyyyy.agents.user.yyyyyyyyyyyyyyyyyyyyyy.agents.user.notifications.sender.received_invitations.user.user_privileges.privilege.user_privileges.user.yyyyyyyyyyyyyyyyyyyyyy.client_website.client_website_employees.clientwebsiteemployees_client_website_employee_teams.client_website_employee_team.clientwebsiteemployeeteams_client_website_zzzzzzzzzzzzzzzzzzzzzzs.client_website_zzzzzzzzzzzzzzzzzzzzzz.zzzzzzzzzzzzzzzzzzzzzz.neighborhood.geography_similarities.similar_geography.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.aaaaaaaaaaaaaaaaaas.neighborhood.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.neighborhood.geography_similarities.similar_geography.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.neighborhood.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.neighborhood.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.aaaaaaaaaaaaaaaaaas.neighborhood.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.neighborhood.geography_similarities.similar_geography.zzzzzzzzzzzzzzzzzzzzzz_geographies.zzzzzzzzzzzzzzzzzzzzzz.aaaaaaaaaaaaaaaaaas.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.user.notifications.sender.notifications.sender.received_invitations.user.bbbbbbbbbbbbbbbb_clients.client.sent_notifications.user.subscriptions.plan.subscriptions.user.search_states.shareables.recipient.received_shareables.bbbbbbbbbbbbbbbb_client.list.bbbbbbbbbbbbbbbb_clients.client.notifications.sender.notifications.sender.search_states.shareables.recipient.received_shareables.bbbbbbbbbbbbbbbb_client.list.bbbbbbbbbbbbbbbb_clients.client.notifications.sender.search_states.shareables.recipient.received_shareables.bbbbbbbbbbbbbbbb_client.list.bbbbbbbbbbbbbbbb_clients.client.notifications.sender.search_states.shareables.recipient.received_shareables.bbbbbbbbbbbbbbbb_client.list.bbbbbbbbbbbbbbbb_clients.client.notifications.sender.subscriptions.plan.subscriptions.user.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.aaaaaaaaaaaaaaaaaa_agents.aaaaaaaaaaaaaaaaaa.zzzzzzzzzzzzzzzzzzzzzz.aaaaaaaaaaaaaaaaaas.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.office_memberships.office.office_memberships.agent.common_agent.agents.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.aaaaaaaaaaaaaaaaaa_agents.aaaaaaaaaaaaaaaaaa.zzzzzzzzzzzzzzzzzzzzzz.aaaaaaaaaaaaaaaaaas.yyyyyyyyyyyyyyyyyyyyyy.agents.common_agent.agents.aaaaaaaaaaaaaaaaaa_agents.aaaaaaaaaaaaaaaaaa.zzzzzzzzzzzzzzzzzzzzzz.aaaaaaaaaaaaaaaaaas

Envek commented 3 months ago

Hey, just a heads up that there is a new option limit_deep to limit association depth from https://github.com/evilmartians/evil-seed/pull/13, hope that it can help in any way.

EvilSeed.configure do |config|
  config.root('Forum', featured: true) do |root|
    # Limit the depth of associations to be dumped from the root level
    # All traverses through has_many, belongs_to, etc are counted
    # So forum.subforums.subforums.questions.answers will be 5 levels deep
    root.limit_deep(10)
  end
end