From 46bf4b727f0fae37b017f194983122c50d3f34e5 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Mon, 20 Jul 2009 04:11:36 +0000 Subject: Initial checkin of _changes filters. The prime weak-spot for this approach is that it maintains an OS-process per connected filtered _changes consumer. I'm pretty sure we'll be able to work around this without changing the API, but it'll involve a lot of OS-process bookkeeping. Those enhancements should generally improve show & list performance as well. Punting on them for now, first wanted to get _changes filters implemented so people could give feedback. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@795687 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_util.erl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/couchdb/couch_util.erl') diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index 817572bb..db9f937c 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -17,7 +17,7 @@ -export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]). -export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]). -export([encodeBase64/1, decodeBase64/1, to_hex/1,parse_term/1,dict_find/3]). --export([file_read_size/1]). +-export([file_read_size/1, get_nested_json_value/2, json_user_ctx/1]). -export([to_binary/1, to_list/1]). -include("couch_db.hrl"). @@ -75,6 +75,22 @@ parse_term(List) -> erl_parse:parse_term(Tokens). +get_nested_json_value({Props}, [Key|Keys]) -> + case proplists:get_value(Key, Props, nil) of + nil -> throw({not_found, <<"missing json key: ", Key/binary>>}); + Value -> get_nested_json_value(Value, Keys) + end; +get_nested_json_value(Value, []) -> + Value; +get_nested_json_value(_NotJSONObj, _) -> + throw({not_found, json_mismatch}). + +json_user_ctx(#db{name=DbName, user_ctx=Ctx}) -> + {[{<<"db">>, DbName}, + {<<"name">>,Ctx#user_ctx.name}, + {<<"roles">>,Ctx#user_ctx.roles}]}. + + % returns a random integer rand32() -> crypto:rand_uniform(0, 16#100000000). -- cgit v1.2.3