summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-10-23 16:49:52 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-10-23 16:49:52 +0000
commitdf38ecb4975f250f7a93b7327f8244d618d5ab99 (patch)
tree33c345aed4a6ca7626bed3c766e63adc2e185e57 /src
parent871603e505f23789dbad26a3242db41e1fb31a83 (diff)
improved speed and concurrency of config lookups
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@829123 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_config.erl21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl
index 5d911455..d8473e08 100644
--- a/src/couchdb/couch_config.erl
+++ b/src/couchdb/couch_config.erl
@@ -50,7 +50,8 @@ all() ->
get(Section) when is_binary(Section) ->
?MODULE:get(?b2l(Section));
get(Section) ->
- gen_server:call(?MODULE, {get, Section}).
+ Matches = ets:match(?MODULE, {{Section, '$1'}, '$2'}),
+ [{Key, Value} || [Key, Value] <- Matches].
get(Section, Key) ->
?MODULE:get(Section, Key, undefined).
@@ -58,8 +59,10 @@ get(Section, Key) ->
get(Section, Key, Default) when is_binary(Section) and is_binary(Key) ->
?MODULE:get(?b2l(Section), ?b2l(Key), Default);
get(Section, Key, Default) ->
- gen_server:call(?MODULE, {get, Section, Key, Default}).
-
+ case ets:lookup(?MODULE, {Section, Key}) of
+ [] -> Default;
+ [{_, Match}] -> Match
+ end.
set(Section, Key, Value) ->
?MODULE:set(Section, Key, Value, true).
@@ -89,7 +92,7 @@ register(Fun, Pid) ->
init(IniFiles) ->
- ets:new(?MODULE, [named_table, set, private]),
+ ets:new(?MODULE, [named_table, set, protected]),
lists:map(fun(IniFile) ->
{ok, ParsedIniValues} = parse_ini_file(IniFile),
ets:insert(?MODULE, ParsedIniValues)
@@ -108,16 +111,6 @@ terminate(_Reason, _State) ->
handle_call(all, _From, Config) ->
Resp = lists:sort((ets:tab2list(?MODULE))),
{reply, Resp, Config};
-handle_call({get, Section}, _From, Config) ->
- Matches = ets:match(?MODULE, {{Section, '$1'}, '$2'}),
- Resp = [{Key, Value} || [Key, Value] <- Matches],
- {reply, Resp, Config};
-handle_call({get, Section, Key, Default}, _From, Config) ->
- Resp = case ets:lookup(?MODULE, {Section, Key}) of
- [] -> Default;
- [{_, Match}] -> Match
- end,
- {reply, Resp, Config};
handle_call({set, Sec, Key, Val, Persist}, _From, Config) ->
true = ets:insert(?MODULE, {{Sec, Key}, Val}),
case {Persist, Config#config.write_filename} of