use safe insert in torrent builder

This commit is contained in:
Kevin Lynx 2013-07-09 17:01:04 +08:00
parent 5d8c198357
commit b9130ec759
2 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -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].