couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1064076 - /couchdb/trunk/src/couchdb/couch_auth_cache.erl
Date Thu, 27 Jan 2011 10:46:43 GMT
Author: fdmanana
Date: Thu Jan 27 10:46:42 2011
New Revision: 1064076

URL: http://svn.apache.org/viewvc?rev=1064076&view=rev
Log:
Trivial small refactoring

Shortening the code by using multiple function clauses.

Modified:
    couchdb/trunk/src/couchdb/couch_auth_cache.erl

Modified: couchdb/trunk/src/couchdb/couch_auth_cache.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_auth_cache.erl?rev=1064076&r1=1064075&r2=1064076&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_auth_cache.erl (original)
+++ couchdb/trunk/src/couchdb/couch_auth_cache.erl Thu Jan 27 10:46:42 2011
@@ -110,11 +110,8 @@ init(_) ->
     ok = couch_config:register(
         fun("couch_httpd_auth", "auth_cache_size", SizeList) ->
             Size = list_to_integer(SizeList),
-            ok = gen_server:call(?MODULE, {new_max_cache_size, Size}, infinity)
-        end
-    ),
-    ok = couch_config:register(
-        fun("couch_httpd_auth", "authentication_db", DbName) ->
+            ok = gen_server:call(?MODULE, {new_max_cache_size, Size}, infinity);
+        ("couch_httpd_auth", "authentication_db", DbName) ->
             ok = gen_server:call(?MODULE, {new_auth_db, ?l2b(DbName)}, infinity)
         end
     ),
@@ -167,26 +164,21 @@ handle_call(auth_db_compacted, _From, St
     ),
     {reply, ok, State};
 
+handle_call({new_max_cache_size, NewSize},
+        _From, #state{cache_size = Size} = State) when NewSize >= Size ->
+    {reply, ok, State#state{max_cache_size = NewSize}};
+
 handle_call({new_max_cache_size, NewSize}, _From, State) ->
-    case NewSize >= State#state.cache_size of
-    true ->
-        ok;
-    false ->
-        lists:foreach(
-            fun(_) ->
-                LruTime = ets:last(?BY_ATIME),
-                [{LruTime, UserName}] = ets:lookup(?BY_ATIME, LruTime),
-                true = ets:delete(?BY_ATIME, LruTime),
-                true = ets:delete(?BY_USER, UserName)
-            end,
-            lists:seq(1, State#state.cache_size - NewSize)
-        )
-    end,
-    NewState = State#state{
-        max_cache_size = NewSize,
-        cache_size = lists:min([NewSize, State#state.cache_size])
-    },
-    {reply, ok, NewState};
+    lists:foreach(
+        fun(_) ->
+            LruTime = ets:last(?BY_ATIME),
+            [{LruTime, UserName}] = ets:lookup(?BY_ATIME, LruTime),
+            true = ets:delete(?BY_ATIME, LruTime),
+            true = ets:delete(?BY_USER, UserName)
+        end,
+        lists:seq(1, State#state.cache_size - NewSize)
+    ),
+    {reply, ok, State#state{max_cache_size = NewSize, cache_size = NewSize}};
 
 handle_call({fetch, UserName}, _From, State) ->
     {Credentials, NewState} = case ets:lookup(?BY_USER, UserName) of



Mime
View raw message