# OSQA 迁移至 Discourse 时点赞数统计问题

**URL:** <https://meta.discourse.org/t/issues-in-like-count-for-osqa-migration-to-discourse/94880>\
**Category:** Development\
**Created:** [2018 年8 月 16 日 15:03 UTC](https://meta.discourse.org/t/issues-in-like-count-for-osqa-migration-to-discourse/94880 "2018-08-16T15:03:20Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

作者： ![praveendhinwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/praveendhinwa/32/108964_2.png) [@praveendhinwa](https://meta.discourse.org/u/praveendhinwa)\
发布日期： [2018 年8 月 18 日 17:51 UTC](https://meta.discourse.org/t/issues-in-like-count-for-osqa-migration-to-discourse/94880/10 "2018-08-18T17:51:14Z")

</div>

@zogstrip: Here is the relevant code for it.

```plaintext
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

```

---

_[View the full topic](https://meta.discourse.org/t/issues-in-like-count-for-osqa-migration-to-discourse/94880)._
