Skip to content

Instantly share code, notes, and snippets.

@fdmanana
Created July 7, 2010 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdmanana/467450 to your computer and use it in GitHub Desktop.
Save fdmanana/467450 to your computer and use it in GitHub Desktop.
doc_infos_after_filter(Req, DocInfo, Db, Style, DDocName, FilterName) ->
DocInfos = case Style of
main_only ->
[DocInfo];
all_docs ->
[DocInfo#doc_info{revs=[Rev]} || Rev <- DocInfo#doc_info.revs]
end,
{_, PosDocInfoDict, Docs1} = lists:foldl(
fun(DI, {P, Dict, Acc}) ->
case couch_db:open_doc(Db, DI, [deleted, conflicts]) of
{ok, Doc} ->
{P + 1, dict:store(P, DI, Dict), [Doc | Acc]};
_ ->
{P, Dict, Acc}
end
end,
{1, dict:new(), []},
DocInfos
),
Docs = lists:reverse(Docs1),
{ok, Passes} = couch_query_servers:filter_docs(
Req, Db, DDoc, FName, Docs
),
{_, Filtered} = lists:foldl(
fun(true, {P, Acc}) ->
{P + 1, [dict:fetch(P, PosDocInfoDict) | Acc]};
(_, {P, Acc} ->
{P + 1, Acc}
end,
{1, []},
Passes
),
lists:reverse(Filtered).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment