From b9130ec759fdbf49f45b415dfde9787be3ede532 Mon Sep 17 00:00:00 2001 From: Kevin Lynx Date: Tue, 9 Jul 2013 17:01:04 +0800 Subject: [PATCH] use safe insert in torrent builder --- src/db_system.erl | 6 +++--- src/tor_builder/tor_builder.erl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/db_system.erl b/src/db_system.erl index 56b1710..1f73937 100644 --- a/src/db_system.erl +++ b/src/db_system.erl @@ -24,15 +24,15 @@ % increase the seed and return the new id get_torrent_id(Conn) -> Cmd = {findAndModify, ?COLLNAME, query, {'_id', ?TORRENT_ID_KEY}, - update, {'$inc', {seed, 1}}, new, false, upsert, true}, + update, {'$inc', {seed, 1}}, new, true, upsert, true}, Ret = mongo:do(safe, master, Conn, ?DBNAME, fun() -> mongo:command(Cmd) end), case bson:lookup(value, Ret) of {undefined} -> - 0; + 1; {} -> - 0; + 1; {Obj} -> {Seed} = bson:lookup(seed, Obj), Seed diff --git a/src/tor_builder/tor_builder.erl b/src/tor_builder/tor_builder.erl index 69a2bb1..5b28c61 100644 --- a/src/tor_builder/tor_builder.erl +++ b/src/tor_builder/tor_builder.erl @@ -160,5 +160,5 @@ try_save([]) -> ok; try_save(Tors) -> Conn = mongo_pool:get(?DBPOOL), - db_store_mongo:unsafe_insert(Conn, Tors). - + [db_store_mongo:insert(Conn, Hash, Name, Length, Files) || + {Hash, Name, Length, Files} <- Tors].