Issues in Like Count for OSQA Migration to Discourse

@zogstrip: Here is the relevant code for it.

def import_likes
    puts "Importing likes..."

    @last_imported_post_id = 0

    post_thanks = mysql_stream <<-SQL
      SELECT
        fa.user_id as user_id,
        fa.node_id as node_id,
        fa.action_date as action_date
        from forum_action fa
        INNER JOIN forum_node fn
        ON fa.node_id = fn.id
        where canceled = 0
        and (action_type = 'voteup' 
          || action_type = 'voteupcomment')
        and fa.node_id > #{@last_imported_post_id}
        ORDER BY fa.node_id ASC
    SQL

    @imported_likes = Set.new
    
    errors = 0
    create_post_actions(post_thanks) do |row|
      post_id = post_id_from_imported_id(row['node_id'])
      user_id = user_id_from_imported_id(row['user_id'])

      if post_id.nil? || user_id.nil?
        errors += 1
        next
      end

      if @imported_likes.add?([post_id, user_id]).nil?
        errors += 1
        next
      end

      # next if post_id.nil? || user_id.nil?
      # next if @imported_likes.add?([post_id, user_id]).nil?

      like = {
        post_id: post_id,
        user_id: user_id,
        post_action_type_id: 2,
        created_at: Time.zone.at(row['action_date'])
      }

      # puts like

      # script_exit
      like
    end

    puts "total errors in likes importing: ", errors

  end