I am trying to cycle through a few of these blocks. They basically narrow down a number of people that fulfill a bunch of attributes.I apologize if this seems really messy, but my database is really taking a toll processing this, and I know there's a better way. I'm just lost on strategy right now.def count_of_distribution      #beginning with an array..  array_of_users = []  # any matching zip codes? ..  # zip_codes  @zip_codes = self.distributions.map(&:zip_code).compact  unless @zip_codes.nil? || @zip_codes.empty?     @matched_zips = CardSignup.all.map(&:zip_code) & @zip_codes    @matched_zips.each do |mz|       CardSignup.find(:all, :conditions => [zip_code = ?, mz]).each do |cs|        array_of_users << cs.id      end    end  end  # any matching interests?..  # interest  @topics = self.distributions.map(&:me_topic).compact  unless  @topics.nil? || @topics.empty?    @matched_topics = MeTopic.all.map(&:name) & @topics    @matched_topics.each do |mt|      MeTopic.find(:all, :conditions => [name = ?, mt]).each do |mt2|        mt2.users.each do |u|          array_of_users << u.card_signup.id if u.card_signup        end      end    end  end  # any matching sexes?..  # sex  @sexes = self.distributions.map(&:sex).compact  unless @sexes.nil? || @sexes.empty?    @matched_sexes = CardSignup.all.map(&:sex) & @sexes    @matched_sexes.each do |ms|      CardSignup.find(:all, :conditions => [sex = ?, ms]).each do |cs|        array_of_users << cs.id      end    end  end  total_number = array_of_users.compact.uniq  return total_numberend
Counting subscribers with matching ZIP code, interests, and sex
ruby;ruby on rails