From a41b4818cc496f07a07c324a8a1f7c82fbf0317a Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Wed, 2 Sep 2009 23:17:25 +0000 Subject: skip some regex etc. if DB is already open git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@810729 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_server.erl | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 93ba67d0..f407acf0 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -202,15 +202,15 @@ handle_call({set_max_dbs_open, Max}, _From, Server) -> handle_call(get_server, _From, Server) -> {reply, {ok, Server}, Server}; handle_call({open, DbName, Options}, _From, Server) -> - DbNameList = binary_to_list(DbName), - case check_dbname(Server, DbNameList) of - ok -> - Filepath = get_full_filename(Server, DbNameList), - LruTime = now(), - case ets:lookup(couch_dbs_by_name, DbName) of - [] -> + LruTime = now(), + case ets:lookup(couch_dbs_by_name, DbName) of + [] -> + DbNameList = binary_to_list(DbName), + case check_dbname(Server, DbNameList) of + ok -> case maybe_close_lru_db(Server) of {ok, Server2} -> + Filepath = get_full_filename(Server, DbNameList), case couch_db:start_link(DbName, Filepath, Options) of {ok, MainPid} -> true = ets:insert(couch_dbs_by_name, {DbName, {MainPid, LruTime}}), @@ -225,14 +225,14 @@ handle_call({open, DbName, Options}, _From, Server) -> CloseError -> {reply, CloseError, Server} end; - [{_, {MainPid, PrevLruTime}}] -> - true = ets:insert(couch_dbs_by_name, {DbName, {MainPid, LruTime}}), - true = ets:delete(couch_dbs_by_lru, PrevLruTime), - true = ets:insert(couch_dbs_by_lru, {LruTime, DbName}), - {reply, {ok, MainPid}, Server} + Error -> + {reply, Error, Server} end; - Error -> - {reply, Error, Server} + [{_, {MainPid, PrevLruTime}}] -> + true = ets:insert(couch_dbs_by_name, {DbName, {MainPid, LruTime}}), + true = ets:delete(couch_dbs_by_lru, PrevLruTime), + true = ets:insert(couch_dbs_by_lru, {LruTime, DbName}), + {reply, {ok, MainPid}, Server} end; handle_call({create, DbName, Options}, _From, Server) -> DbNameList = binary_to_list(DbName), -- cgit v1.2.3