Skip to content

Instantly share code, notes, and snippets.

@rnewson
Created November 20, 2014 23:42
Show Gist options
  • Select an option

  • Save rnewson/9e3d73bb826814419dcf to your computer and use it in GitHub Desktop.

Select an option

Save rnewson/9e3d73bb826814419dcf to your computer and use it in GitHub Desktop.
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index 8fe4b18..2dd14cd 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -63,7 +63,16 @@ validate(DbName, DDoc) ->
lists:foldl(ValidateFun, ok, EnabledIndexers).
-get_index(Module, <<"shards/", _/binary>>=DbName, DDoc) ->
+get_index(Module, <<"shards/", _/binary>> = DbName, DDoc) ->
+ get_index_fabric(Module, DbName, DDoc);
+get_index(Module, #db{name = <<"shards/", _/binary>> = DbName}, DDoc) ->
+ get_index_fabric(Module, DbName, DDoc);
+
+
+get_index(Module, DbName, DDoc) ->
+ get_index(Module, DbName, DDoc, nil).
+
+get_index_fabric(Module, DbName, DDoc) ->
{Pid, Ref} = spawn_monitor(fun() ->
exit(fabric:open_doc(mem3:dbname(DbName), DDoc, [ejson_body]))
end),
@@ -74,11 +83,7 @@ get_index(Module, <<"shards/", _/binary>>=DbName, DDoc) ->
after 61000 ->
erlang:demonitor(Ref, [flush]),
{error, timeout}
- end;
-
-get_index(Module, DbName, DDoc) ->
- get_index(Module, DbName, DDoc, nil).
-
+ end.
get_index(Module, DbName, DDoc, Fun) when is_binary(DbName) ->
couch_util:with_db(DbName, fun(Db) ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment