Skip to content
Browse files

skip checking for duplicate when loading a collection from scratch

  • Loading branch information...
1 parent 3ab6d2b commit 72e569e6d8508a65ec35a4e8da7f46b71eb53657 @erwaller erwaller committed
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/soulmate/loader.rb
View
9 lib/soulmate/loader.rb
@@ -21,7 +21,7 @@ def load(items)
items_loaded = 0
items.each_with_index do |item, i|
- add(item)
+ add(item, :skip_duplicate_check => true)
items_loaded += 1
puts "added #{i} entries" if i % 100 == 0 and i != 0
end
@@ -30,11 +30,12 @@ def load(items)
end
# "id", "term", "score", "aliases", "data"
- def add(item = {})
+ def add(item, opts = {})
+ opts = { :skip_duplicate_check => false }.merge(opts)
raise ArgumentError unless item["id"] && item["term"]
# kill any old items with this id
- remove(item["id"])
+ remove(item["id"]) unless opts[:skip_duplicate_check]
# store the raw data in a separate key to reduce memory usage
Soulmate.redis.hset(database, item["id"], JSON.dump(item))
@@ -45,7 +46,7 @@ def add(item = {})
end
end
- def remove(id)
+ def remove(id, opts = {})
prev_item = Soulmate.redis.hget(database, id)
if prev_item
prev_item = JSON.load(prev_item)

0 comments on commit 72e569e

Please sign in to comment.
Something went wrong with that request. Please try again.