Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D22C17872 for ; Wed, 22 Oct 2014 18:19:34 +0000 (UTC) Received: (qmail 40845 invoked by uid 500); 22 Oct 2014 18:19:33 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 40784 invoked by uid 500); 22 Oct 2014 18:19:33 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 40766 invoked by uid 99); 22 Oct 2014 18:19:33 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Oct 2014 18:19:33 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 21A679B2F5E; Wed, 22 Oct 2014 18:19:32 +0000 (UTC) From: davisp To: dev@couchdb.apache.org Reply-To: dev@couchdb.apache.org References: In-Reply-To: Subject: [GitHub] couchdb-couch-mrview pull request: Add view changes functionality Content-Type: text/plain Message-Id: <20141022181933.21A679B2F5E@tyr.zones.apache.org> Date: Wed, 22 Oct 2014 18:19:32 +0000 (UTC) Github user davisp commented on a diff in the pull request: https://github.com/apache/couchdb-couch-mrview/pull/2#discussion_r19233379 --- Diff: src/couch_mrview.erl --- @@ -135,11 +140,67 @@ query_view(Db, {Type, View, Ref}, Args, Callback, Acc) -> erlang:demonitor(Ref, [flush]) end. +view_changes_since(View, StartSeq, Fun, Opts0, Acc) -> + Wrapper = fun(KV, _, Acc1) -> + Fun(KV, Acc1) + end, + Opts = [{start_key, {StartSeq + 1, <<>>}}] ++ Opts0, + {ok, _LastRed, AccOut} = couch_btree:fold(View#mrview.seq_btree, Wrapper, Acc, Opts), + {ok, AccOut}. + +view_changes_since(Db, DDoc, VName, StartSeq, Fun, Acc) -> + view_changes_since(Db, DDoc, VName, StartSeq, Fun, [], Acc). + +view_changes_since(Db, DDoc, VName, StartSeq, Fun, Options, Acc) -> + Args0 = make_view_changes_args(Options), + {ok, {_, View, _}, _, Args} = couch_mrview_util:get_view(Db, DDoc, VName, + Args0), + #mrview{seq_indexed=SIndexed, keyseq_indexed=KSIndexed} = View, + IsKSQuery = is_key_byseq(Options), + if (SIndexed andalso not IsKSQuery) orelse (KSIndexed andalso IsKSQuery) -> + OptList = make_view_changes_opts(StartSeq, Options, Args), + Btree = case IsKSQuery of + true -> View#mrview.key_byseq_btree; + _ -> View#mrview.seq_btree + end, + AccOut = lists:foldl(fun(Opts, Acc0) -> + {ok, _R, A} = couch_mrview_util:fold_changes( + Btree, Fun, Acc0, Opts), + A + end, Acc, OptList), + {ok, AccOut}; + true -> + {error, seqs_not_indexed} + end. + +count_view_changes_since(Db, DDoc, VName, SinceSeq) -> + count_view_changes_since(Db, DDoc, VName, SinceSeq, []). + +count_view_changes_since(Db, DDoc, VName, SinceSeq, Options) -> + Args0 = make_view_changes_args(Options), + {ok, {_, View}, _, Args} = couch_mrview_util:get_view(Db, DDoc, VName, + Args0), + case View#mrview.seq_indexed of + true -> + OptList = make_view_changes_opts(SinceSeq, Options, Args), + Btree = case is_key_byseq(Options) of + true -> View#mrview.key_byseq_btree; + _ -> View#mrview.seq_btree + end, + lists:foldl(fun(Opts, Acc0) -> + {ok, N} = couch_btree:fold_reduce( + Btree, fun(_SeqStart, PartialReds, 0) -> + {ok, couch_btree:final_reduce( + Btree, PartialReds)} + end, + 0, Opts), + Acc0 + N + end, 0, OptList); --- End diff -- This indentation "style" displeases me. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---