couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [04/18] git commit: Support caching validation functions
Date Fri, 17 Jan 2014 21:41:30 GMT
Support caching validation functions


Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/3ea44df9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/3ea44df9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/3ea44df9

Branch: refs/heads/import
Commit: 3ea44df9dea153d14d424cb5de0e9e3504e17cb9
Parents: 30ac844
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Wed Jan 23 14:11:28 2013 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Jan 23 16:02:51 2013 -0600

----------------------------------------------------------------------
 src/ddoc_cache.erl        | 21 ++++++++++++++-------
 src/ddoc_cache_opener.erl | 10 ++++++++++
 2 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/3ea44df9/src/ddoc_cache.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.erl b/src/ddoc_cache.erl
index 14c7c82..a3b99d6 100644
--- a/src/ddoc_cache.erl
+++ b/src/ddoc_cache.erl
@@ -23,12 +23,19 @@ stop() ->
     application:stop(ddoc_cache).
 
 
+open(DbName, validation_funs) ->
+    open({DbName, validation_funs});
 open(DbName, <<"_design/", _/binary>>=DDocId) when is_binary(DbName) ->
-    case ets_lru:lookup_d(?CACHE, {DbName, DDocId}) of
-        {ok, Doc} ->
-            {ok, Doc};
-        _ ->
-            gen_server:call(?OPENER, {open, {DbName, DDocId}}, infinity)
-    end;
+    open({DbName, DDocId});
 open(DbName, DDocId) when is_binary(DDocId) ->
-    open(DbName, <<"_design/", DDocId/binary>>).
+    open({DbName, <<"_design/", DDocId/binary>>}).
+
+
+open(Key) ->
+    case ets_lru:lookup_d(?CACHE, Key) of
+        {ok, _} = Resp ->
+            Resp;
+        _ ->
+            gen_server:call(?OPENER, {open, Key}, infinity)
+    end.
+

http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/3ea44df9/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 01c714f..77b025f 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -94,6 +94,16 @@ code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
 
+open_ddoc({DbName, validation_funs}=Key) ->
+    {ok, DDocs} = fabric:design_docs(mem3:dbname(DbName)),
+    Funs = lists:flatmap(fun(DDoc) ->
+        case couch_doc:get_validate_doc_fun(DDoc) of
+            nil -> [];
+            Fun -> [Fun]
+        end
+    end, DDocs),
+    ok = ets_lru:insert(ddoc_cache_lru, {DbName, validation_funs}, Funs),
+    exit({ddoc_ok, Key, Funs});
 open_ddoc({DbName, DDocId}=Key) ->
     case fabric:open_doc(DbName, DDocId) of
         {ok, Doc} ->


Mime
View raw message