summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-06-22 08:05:44 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-06-22 13:59:33 -0700
commit096343af965c9f371c74e7fd9bd45bbe67f3470f (patch)
tree6a62b4625e5631c9b13a8c9e4f41bf0605186b4c
parentb7d46723fc704eb37555ac5dce96eab1724bdc2e (diff)
allow a #doc{} instead of docid in get_view_group_info
-rw-r--r--src/fabric.erl11
-rw-r--r--src/fabric_group_info.erl7
2 files changed, 15 insertions, 3 deletions
diff --git a/src/fabric.erl b/src/fabric.erl
index afa87082..badc1379 100644
--- a/src/fabric.erl
+++ b/src/fabric.erl
@@ -96,7 +96,7 @@ query_view(DbName, Design, ViewName, QueryArgs, Callback, Acc0) ->
Mod:go(Db, Design, View, QueryArgs, Callback, Acc0).
get_view_group_info(DbName, DesignId) ->
- fabric_group_info:go(dbname(DbName), name(DesignId)).
+ fabric_group_info:go(dbname(DbName), design_doc(DesignId)).
design_docs(DbName) ->
QueryArgs = #view_query_args{start_key = <<"_design/">>, include_docs=true},
@@ -147,6 +147,15 @@ doc({_} = Doc) ->
doc(Doc) ->
erlang:error({illegal_doc_format, Doc}).
+design_doc(#doc{} = DDoc) ->
+ DDoc;
+design_doc(DocId) when is_list(DocId) ->
+ design_doc(list_to_binary(DocId));
+design_doc(<<"_design/", _/binary>> = DocId) ->
+ DocId;
+design_doc(GroupName) ->
+ <<"_design/", GroupName/binary>>.
+
idrevs({Id, Revs}) when is_list(Revs) ->
{docid(Id), [rev(R) || R <- Revs]}.
diff --git a/src/fabric_group_info.erl b/src/fabric_group_info.erl
index 42c29838..d2b76674 100644
--- a/src/fabric_group_info.erl
+++ b/src/fabric_group_info.erl
@@ -4,8 +4,11 @@
-include("fabric.hrl").
-go(DbName, GroupId) ->
- {ok, DDoc} = fabric:open_doc(DbName, <<"_design/", GroupId/binary>>, []),
+go(DbName, GroupId) when is_binary(GroupId) ->
+ {ok, DDoc} = fabric:open_doc(DbName, GroupId, []),
+ go(DbName, DDoc);
+
+go(DbName, #doc{} = DDoc) ->
Group = couch_view_group:design_doc_to_view_group(#db{name=DbName}, DDoc),
Shards = partitions:all_parts(DbName),
Workers = fabric_util:submit_jobs(Shards, group_info, [Group]),