From feb18bd6efc40126bdb4af390419223e10ef134d Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Wed, 23 Jun 2010 19:11:50 +0000 Subject: Authentication caching, to avoid repeated opening and closing of the users database for each request requiring authentication. COUCHDB-807 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@957314 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd_db.erl | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) (limited to 'src/couchdb/couch_httpd_db.erl') diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 87fc15d8..06d56c7b 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -160,23 +160,13 @@ handle_design_info_req(Req, _Db, _DDoc) -> create_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) -> ok = couch_httpd:verify_is_server_admin(Req), - LDbName = ?b2l(DbName), - case couch_config:get("couch_httpd_auth", "authentication_db") of - LDbName -> - % make sure user's db always has the auth ddoc - {ok, Db} = couch_httpd_auth:ensure_users_db_exists(DbName), - couch_db:close(Db), - DbUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)), - send_json(Req, 201, [{"Location", DbUrl}], {[{ok, true}]}); - _Else -> - case couch_server:create(DbName, [{user_ctx, UserCtx}]) of - {ok, Db} -> - couch_db:close(Db), - DbUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)), - send_json(Req, 201, [{"Location", DbUrl}], {[{ok, true}]}); - Error -> - throw(Error) - end + case couch_server:create(DbName, [{user_ctx, UserCtx}]) of + {ok, Db} -> + couch_db:close(Db), + DbUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)), + send_json(Req, 201, [{"Location", DbUrl}], {[{ok, true}]}); + Error -> + throw(Error) end. delete_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) -> @@ -189,15 +179,6 @@ delete_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) -> end. do_db_req(#httpd{user_ctx=UserCtx,path_parts=[DbName|_]}=Req, Fun) -> - LDbName = ?b2l(DbName), - % I hope this lookup is cheap. - case couch_config:get("couch_httpd_auth", "authentication_db") of - LDbName -> - % make sure user's db always has the auth ddoc - {ok, ADb} = couch_httpd_auth:ensure_users_db_exists(DbName), - couch_db:close(ADb); - _Else -> ok - end, case couch_db:open(DbName, [{user_ctx, UserCtx}]) of {ok, Db} -> try -- cgit v1.2.3