anchor.diff:  
   %% @hidden
   get_acct_query([] = _Query, Filters) ->
  -	{ok, _MaxItems} = application:get_env(ocs, rest_page_size),
  -	case ocs_log:auth_query(1, 1, '_', '_', '_', '_') of
  -		[] ->
  +	{ok, MaxItems} = application:get_env(ocs, rest_page_size),
  +	Now = erlang:system_time(?MILLISECOND),
  +	case query_acct(1, Now, '_', '_', '_', MaxItems) of
  +		{0, []} ->
   			{error, 404};
  -		Events ->
  +		{NumItems, Events} ->
   			JsonObj = usage_aaa_acct(Events, Filters),
   			JsonArray = {array, JsonObj},
   			Body = mochijson:encode(JsonArray),
  -			N = integer_to_list(length(Events)),
  +			N = integer_to_list(NumItems),
   			ContentRange = "items 1-" ++ N ++ "/" ++ N,
   			Headers = [{content_type, "application/json"},
   					{content_range, ContentRange}],
  
positive.code: 
  %% @hidden
  get_auth_query([] = _Query, Filters) ->
  	{ok, _MaxItems} = application:get_env(ocs, rest_page_size),
  	case ocs_log:auth_query(1, 1, '_', '_', '_', '_') of
  		[] ->
  			{error, 404};
  		Events ->
  			JsonObj = usage_aaa_auth(Events, Filters),
  			JsonArray = {array, JsonObj},
  			Body = mochijson:encode(JsonArray),
  			N = integer_to_list(length(Events)),
  			ContentRange = "items 1-" ++ N ++ "/" ++ N,
  			Headers = [{content_type, "application/json"},
  					{content_range, ContentRange}],
  
negative.code: filter([], _, Acc) ->
  	lists:reverse(Acc).
  
  %% @hidden
  query_auth(Start, End, Protocol, Types, ReqAttrs, ResAttrs, PageSize) ->
  	query_auth(start, Start, End, Protocol, Types,
  			ReqAttrs, ResAttrs, PageSize, 0, []).
  %% @hidden
  query_auth(Cont, Start, End, Protocol, Types,
  		ReqAttrs, ResAttrs, PageSize, Count, Acc) ->
  	case ocs_log:auth_query(Cont, Start, End,
  			Protocol, Types, ReqAttrs, ResAttrs) of
  		{error, Reason} ->
  			{error, Reason};
  		{Cont1, Events} ->
  			{NewCount, NewAcc} = case length(Events) + Count of
  				Total when Total =< PageSize ->
  					{Total, [Events | Acc]};
  				Total ->
  					{Total, [lists:sublist(Events, PageSize - Count) | Acc]}
  			end,
  			case Cont1 of
  				eof ->
  					{NewCount, lists:flatten(lists:reverse(NewAcc))};
  				_ when NewCount >= PageSize ->
  					{NewCount, lists:flatten(lists:reverse(NewAcc))};
  				_ ->
  					query_auth(Cont1, Start, End, Protocol, Types,
  							ReqAttrs, ResAttrs, PageSize, NewCount, NewAcc)
  			end
  	end.
  
  %% @hidden
  query_acct(Start, End, Protocol, Types, Attrs, PageSize) ->
  	query_acct(start, Start, End, Protocol, Types, Attrs, PageSize, 0, []).
  %% @hidden
  query_acct(Cont, Start, End, Protocol, Types, Attrs, PageSize, Count, Acc) ->
  	case ocs_log:acct_query(Cont, Start, End, Protocol, Types, Attrs) of
  		{error, Reason} ->
  			{error, Reason};
  		{Cont1, Events} ->
  			{NewCount, NewAcc} = case length(Events) + Count of
  				Total when Total =< PageSize ->
  					{Total, [Events | Acc]};
  				Total ->
  					{Total, [lists:sublist(Events, PageSize - Count) | Acc]}
  			end,
  			case Cont1 of
  				eof ->
  					{NewCount, lists:flatten(lists:reverse(NewAcc))};
  				_ when NewCount >= PageSize ->
  					{NewCount, lists:flatten(lists:reverse(NewAcc))};
  				_ ->
  					query_acct(Cont1, Start, End, Protocol, Types,
  							Attrs, PageSize, NewCount, NewAcc)
  			end
  	end.
  
  