mirror of
https://github.com/btdig/dhtcrawler2.git
synced 2025-02-07 13:59:08 +00:00
use safe insert in torrent builder
This commit is contained in:
parent
5d8c198357
commit
b9130ec759
@ -24,15 +24,15 @@
|
|||||||
% increase the seed and return the new id
|
% increase the seed and return the new id
|
||||||
get_torrent_id(Conn) ->
|
get_torrent_id(Conn) ->
|
||||||
Cmd = {findAndModify, ?COLLNAME, query, {'_id', ?TORRENT_ID_KEY},
|
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() ->
|
Ret = mongo:do(safe, master, Conn, ?DBNAME, fun() ->
|
||||||
mongo:command(Cmd)
|
mongo:command(Cmd)
|
||||||
end),
|
end),
|
||||||
case bson:lookup(value, Ret) of
|
case bson:lookup(value, Ret) of
|
||||||
{undefined} ->
|
{undefined} ->
|
||||||
0;
|
1;
|
||||||
{} ->
|
{} ->
|
||||||
0;
|
1;
|
||||||
{Obj} ->
|
{Obj} ->
|
||||||
{Seed} = bson:lookup(seed, Obj),
|
{Seed} = bson:lookup(seed, Obj),
|
||||||
Seed
|
Seed
|
||||||
|
@ -160,5 +160,5 @@ try_save([]) ->
|
|||||||
ok;
|
ok;
|
||||||
try_save(Tors) ->
|
try_save(Tors) ->
|
||||||
Conn = mongo_pool:get(?DBPOOL),
|
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].
|
||||||
|
Loading…
Reference in New Issue
Block a user