Skip to content
This repository has been archived by the owner on Jan 22, 2018. It is now read-only.

Commit

Permalink
make comment fetcher a whole bunch more effecient
Browse files Browse the repository at this point in the history
  • Loading branch information
Undo1 committed Mar 8, 2015
1 parent e8da7cc commit 2c99171
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,33 @@ def self.get_comments_for_site(site)
http.request(req)
}

existing_comments = Comment.select(:comment_id).limit(100).where(site: site.id).map { |c| c.comment_id }

comments = JSON.parse(res.body)["items"]

comments.each do |comment|
puts comment["comment_id"]
if Comment.find_by_comment_id(comment["comment_id"]) == nil
c=Comment.new
c.site = site.id
c.comment_id = comment["comment_id"]
c.text = comment["body"]
c.user_id = comment["owner"]["user_id"]
c.owner_username = comment["owner"]["display_name"]
c.creation_date = DateTime.strptime(comment["creation_date"].to_s, "%s")
ActiveRecord::Base.transaction do
comments.each do |comment|
puts comment["comment_id"]
if not existing_comments.include? comment["comment_id"]
c=Comment.new
c.site = site.id
c.comment_id = comment["comment_id"]
c.text = comment["body"]
c.user_id = comment["owner"]["user_id"]
c.owner_username = comment["owner"]["display_name"]
c.creation_date = DateTime.strptime(comment["creation_date"].to_s, "%s")

flag_reason = self.checkbody(c.text, site)
flag_reason = self.checkbody(c.text, site)

if flag_reason != nil
c.is_flagged = true
c.flag_reason = flag_reason
else
c.is_flagged = false
end
if flag_reason != nil
c.is_flagged = true
c.flag_reason = flag_reason
else
c.is_flagged = false
end

c.save!
c.save!
end
end
end
end
Expand Down

0 comments on commit 2c99171

Please sign in to comment.