Refreshing remote :through associations with deletes

Hi everyone,

I’m refreshing the local Rails database from a remote database every
10 minutes. I’m using a :through association to relate people to
mailinglists through subscriptions.

Works fine, every 10 minutes:

remote_lists.each { |list| List.find_or_create_by_name(list.name) }
remote_subscribers.each do |subscriber|
person = Person.find_by_email(subscriber.user)
unless person.nil?
Subscription.find_or_create_by_person_id_and_mailinglist_id(person.id,
local_list.id)
end
end

remote_lists.each do |list|
local_list = Mailinglist.find_or_create_by_name(list.list)
subscribers =
MailinglistSubscriptionRemote.find_all_by_list_subscriber(local_list.name)
if subscribers.size > 0
subscribers.each do |subscriber|
person = Person.find_by_email(subscriber.user)
unless person.nil?
Subscription.find_or_create_by_person_id_and_mailinglist_id(person.id,
local_list.id)
end
end
end
end

What I need to do is make sure that if [email protected] unsubscribes from
a list, the associated Subscription is removed. I know I’m not
accounting for that here. How should I do that?

Thanks!

Sean