add more upsert_all
This commit is contained in:
parent
3c6828f0fd
commit
fe415b0c13
3 changed files with 18 additions and 32 deletions
|
@ -86,11 +86,13 @@ class CpeImporter
|
||||||
cpe_attrs_from_item(item)
|
cpe_attrs_from_item(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
Cpe.bulk_insert do |worker|
|
Cpe.upsert_all(cpes)
|
||||||
cpes.each do |attrs|
|
|
||||||
worker.add(attrs)
|
#Cpe.bulk_insert do |worker|
|
||||||
end
|
# cpes.each do |attrs|
|
||||||
end
|
# worker.add(attrs)
|
||||||
|
# end
|
||||||
|
#end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cpe_attrs_from_item(item)
|
def self.cpe_attrs_from_item(item)
|
||||||
|
|
|
@ -24,26 +24,17 @@ class GithubUserImporter
|
||||||
|
|
||||||
def user_h_to_attr(user_h)
|
def user_h_to_attr(user_h)
|
||||||
attrs = {}
|
attrs = {}
|
||||||
attrs[:github_id] = user_h['id']
|
attrs[:github_id] = user_h.dig('id')
|
||||||
attrs[:login] = user_h['login']
|
attrs[:login] = user_h.dig('login')
|
||||||
attrs[:name] = user_h['name']
|
attrs[:name] = user_h.dig('name')
|
||||||
attrs[:avatar_url] = user_h['avatarUrl']
|
attrs[:avatar_url] = user_h.dig('avatarUrl')
|
||||||
attrs[:bio] = user_h['bio']
|
attrs[:bio] = user_h.dig('bio')
|
||||||
attrs[:bio_html] = user_h['bioHTML']
|
attrs[:bio_html] = user_h.dig('bioHTML')
|
||||||
attrs[:location] = user_h['location']
|
attrs[:location] = user_h.dig('location')
|
||||||
attrs[:repositories] = user_h['repositories']
|
attrs[:repositories] = user_h.dig('repositories')
|
||||||
attrs
|
attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_insert(username_hashes)
|
|
||||||
GithubUser.bulk_insert do |worker|
|
|
||||||
username_hashes.each do |username_hash|
|
|
||||||
attrs = user_h_to_attr(username_hash)
|
|
||||||
worker.add(attrs)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def import
|
def import
|
||||||
if filepath.nil?
|
if filepath.nil?
|
||||||
puts 'Please provide a filepath in the projects data dir named github_usernames.txt with one username per line.'
|
puts 'Please provide a filepath in the projects data dir named github_usernames.txt with one username per line.'
|
||||||
|
@ -51,7 +42,8 @@ class GithubUserImporter
|
||||||
puts 'Now importing GithubUsers'
|
puts 'Now importing GithubUsers'
|
||||||
usernames = username_hashes.map { |h| h['login'] }
|
usernames = username_hashes.map { |h| h['login'] }
|
||||||
puts "Now importing data from the following usernames: #{usernames}"
|
puts "Now importing data from the following usernames: #{usernames}"
|
||||||
bulk_insert(username_hashes)
|
username_attrs = username_hashes.map { |user_h| user_h_to_attr(user_h) }
|
||||||
|
GithubUser.upsert_all(username_attrs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,14 +30,6 @@ class InthewildCveExploitImporter
|
||||||
cve_attrs
|
cve_attrs
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_insert(cves)
|
|
||||||
InthewildCveExploit.bulk_insert do |worker|
|
|
||||||
cves.each do |attrs|
|
|
||||||
worker.add(attrs)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def import
|
def import
|
||||||
feed = get_exploit_feed
|
feed = get_exploit_feed
|
||||||
puts 'Now importing InthewildCveExploits.'
|
puts 'Now importing InthewildCveExploits.'
|
||||||
|
@ -45,6 +37,6 @@ class InthewildCveExploitImporter
|
||||||
cve_attrs_from_item(cve_entry)
|
cve_attrs_from_item(cve_entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
bulk_insert(cves)
|
InthewildCveExploit.upsert_all(cves)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue