fix hash_date

src
Kevin Lynx 11 years ago
parent 37ccb19575
commit 54a30122fa

@ -5,7 +5,7 @@
%% To track the most recently hashes
%%
-module(db_daterange).
-export([insert/3,
-export([insert/4,
lookup/3]).
-export([start_link/1,
stop/0]).
@ -31,11 +31,11 @@ ensure_date_index(Conn) ->
end).
% '_id': Hash, date: DaySecs, reqs: RequestCount
insert(Conn, Hash, ReqCnt) when is_list(Hash) ->
insert(Conn, Hash, ReqCnt, UpSert) when is_list(Hash) ->
DaySecs = time_util:now_day_seconds(),
BHash = list_to_binary(Hash),
% only record today new inserted torrent
Cmd = {findAndModify, ?COLLNAME, query, {'_id', BHash}, % upsert, true,
Cmd = {findAndModify, ?COLLNAME, query, {'_id', BHash}, upsert, UpSert,
update, {'$inc', {reqs, ReqCnt}, '$set', {?DATE_COL, DaySecs}}, fields, {'_id', 1}},
IRet = mongo:do(safe, master, Conn, ?DBNAME, fun() ->
mongo:command(Cmd)

@ -116,7 +116,7 @@ index(Conn, Hash) when is_list(Hash) ->
insert(Conn, Hash, Name, Length, Files) when is_list(Hash) ->
NewDoc = create_torrent_desc(Conn, Hash, Name, Length, 1, Files),
% TODO: because of the hash_cache_writer, the new inserted torrent lost the req_cnt value
db_daterange:insert(Conn, Hash, 1),
db_daterange:insert(Conn, Hash, 1, true),
mongo_do(Conn, fun() ->
% the doc may already exist because the other process has inserted before
Sel = {'_id', list_to_binary(Hash)},
@ -146,7 +146,7 @@ inc_announce(Conn, Hash, Inc) when is_list(Hash) ->
case Ret of
{value, undefined, ok, 1.0} -> false;
{value, _Obj, lastErrorObject, {updatedExisting, true, n, 1}, ok, 1.0} ->
db_daterange:insert(Conn, Hash, Inc),
db_daterange:insert(Conn, Hash, Inc, false),
true;
_ -> false
end.
@ -333,9 +333,9 @@ test_index(Hash) ->
index(Conn, Hash)
end).
test_insertdate(Hash) ->
test_insertdate(Hash, UpSert) ->
test_content(fun(Conn) ->
db_daterange:insert(Conn, Hash)
db_daterange:insert(Conn, Hash, 1, UpSert)
end).
-ifdef(SPHINX).

Loading…
Cancel
Save