Skip to content

Commit

Permalink
Reduce memory usage by looking up in batches of 20
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismytton committed Jun 15, 2017
1 parent 7615541 commit 96bd912
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scraper.rb
Expand Up @@ -76,7 +76,9 @@ def name_text
wikidata_ids = mayors.map { |m| m[:commune_wikidata] }

# P374 is the INSEE municipality code in Wikidata
insee_code_lookup = Wikisnakker::Item.find(wikidata_ids).map { |i| [i.id, i.P374.to_s] }.to_h
insee_code_lookup = wikidata_ids.each_slice(20).flat_map do |ids|
Wikisnakker::Item.find(ids).map { |i| [i.id, i.P374.to_s] }
end.to_h

mayors.each do |m|
ScraperWiki.save_sqlite([:id], m.merge(insee_code: insee_code_lookup[m[:commune_wikidata]]))
Expand Down

0 comments on commit 96bd912

Please sign in to comment.