visitors = p.visitors.customers.where(tags: 'UNSUBSCRIBE 2021') visitor_ids = visitors.pluck(:id);1 STATUSES_FOR_DELETION = [Automations::Trigger::Status::NOT_EXECUTED, Automations::Trigger::Status::RETRIGGERED].freeze scheduled_steps = Automations::ScheduledStep.in(campaign_id: campaign_ids).in('triggers.visitor_id': visitor_ids) scheduled_steps.map do |step| step.triggers.where(visitor: @visitor).in(status: STATUSES_FOR_DELETION).destroy_all end Mails::SingleEmail.where(project: p, sent_at: nil, processing: false).in(recipient_id: visitor_ids).destroy_all Debug::MergeLog.where(project: p).in(legacy_visitor: visitor_ids).destroy_all visitors.each.with_index do |visitor, index| visitor.events.destroy_all visitor.destroy puts index if index % 1000 == 0 end
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter