Browse Source

Merge branch 'master' of https://github.com/synrc/kvs

Namdak Tonpa 9 years ago
parent
commit
e3da5296b8
7 changed files with 25 additions and 26 deletions
  1. 7 2
      src/kvs.erl
  2. 0 2
      src/kvs_acl.erl
  3. 11 10
      src/kvs_feed.erl
  4. 1 4
      src/kvs_subscription.erl
  5. 2 7
      src/kvs_sup.erl
  6. 0 1
      src/kvs_user.erl
  7. 4 0
      sys.config

+ 7 - 2
src/kvs.erl

@@ -143,7 +143,7 @@ link(Record,#kvs{mod=_Store}=Driver) ->
               {ok, Exists} -> ensure_link(Exists, Driver);
         {error, not_found} -> {error, not_found} end.
 
-add(Record, #kvs{mod=store_mnesia}=Driver) when is_tuple(Record) -> store_mnesia:add(Record);
+%add(Record, #kvs{mod=store_mnesia}=Driver) when is_tuple(Record) -> store_mnesia:add(Record);
 add(Record, #kvs{mod=Store}=Driver) when is_tuple(Record) -> append(Record,Driver).
 
 append(Record, #kvs{mod=_Store}=Driver) when is_tuple(Record) ->
@@ -332,7 +332,7 @@ id_seq(Tab)    -> T = atom_to_list(Tab), case kvs:get(id_seq,T) of {ok,#id_seq{i
 last_disc(T)   -> list_to_atom(lists:concat([T,omitone(kvs:id_seq(list_to_atom(lists:concat([T,".tables"]))))])).
 last_table(T)  -> list_to_atom(lists:concat([T,omitone(lists:max(proplists:get_value(T,fold_tables(),[1])))])).
 fold_tables()  -> lists:foldl(fun(#table{name=X},Acc) ->
-                  wf:setkey(kvs:rname(X),1,Acc,{kvs:rname(X),[kvs:nname(X)|proplists:get_value(kvs:rname(X),Acc,[])]}) end,
+                  setkey(kvs:rname(X),1,Acc,{kvs:rname(X),[kvs:nname(X)|proplists:get_value(kvs:rname(X),Acc,[])]}) end,
                   [], kvs:tables()).
 interval(L,R,Name) -> #interval{left=L,right=R,name=Name,last=last_table(rname(Name))}.
 update_config(Table,Name) ->
@@ -344,3 +344,8 @@ update_config(Table,Name) ->
 update_list(Table,[],Name)                    -> [ interval(top(Table)+1,limit(),Name) ];
 update_list(Table,[#interval{}=CI|Tail],Name) -> [ interval(top(Table)+1,limit(),Name) ] ++
                                                  [ CI#interval{right=top(Table)}       ] ++ Tail.
+
+setkey(Name,Pos,List,New) ->
+    case lists:keyfind(Name,Pos,List) of
+        false -> [New|List];
+        _Element -> lists:keyreplace(Name,Pos,List,New) end.

+ 0 - 2
src/kvs_acl.erl

@@ -5,8 +5,6 @@
 -include("metainfo.hrl").
 -include("acl.hrl").
 -include("user.hrl").
--include("group.hrl").
--include("feed.hrl").
 
 metainfo() ->
     #schema{name=kvs,tables=[

+ 11 - 10
src/kvs_feed.erl

@@ -1,19 +1,20 @@
 -module(kvs_feed).
 -copyright('Synrc Research Center, s.r.o.').
 -compile(export_all).
+-include("kvs.hrl").
 -include("config.hrl").
 -include("entry.hrl").
 -include("comment.hrl").
 -include("feed.hrl").
 -include("metainfo.hrl").
--include("kvs.hrl").
 
-metainfo() ->
-    #schema{name=kvs,tables=[
-        #table{name=entry,container=true,fields=record_info(fields,entry)},
-        #table{name=config,fields=record_info(fields,config)},
-        #table{name=log,container=true,fields=record_info(fields,log)},
-        #table{name=operation,container=log,fields=record_info(fields,operation)},
-        #table{name=comment,container=true,fields=record_info(fields,comment)},
-        #table{name=feed,container=true,fields=record_info(fields,feed)}
-    ]}.
+metainfo() ->  #schema{name=kvs,tables= core() ++ feeds() }.
+
+core()     -> [ #table{name=config,fields=record_info(fields,config)},
+                #table{name=log,container=true,fields=record_info(fields,log)},
+                #table{name=operation,container=log,fields=record_info(fields,operation)},
+                #table{name=id_seq,fields=record_info(fields,id_seq),keys=[thing]} ].
+
+feeds()    -> [ #table{name=entry,container=true,fields=record_info(fields,entry)},
+                #table{name=comment,container=true,fields=record_info(fields,comment)},
+                #table{name=feed,container=true,fields=record_info(fields,feed)} ].

+ 1 - 4
src/kvs_subscription.erl

@@ -1,14 +1,12 @@
 -module(kvs_subscription).
 -copyright('Synrc Research Center s.r.o.').
 -include("subscription.hrl").
--include("user.hrl").
 -include("metainfo.hrl").
 -compile(export_all).
 
 metainfo() ->
     #schema{name=kvs,tables=[
-        #table{name=subscription,fields=record_info(fields,subscription),keys=[id,whom,who]},
-        #table{name=id_seq,fields=record_info(fields,id_seq),keys=[thing]}
+        #table{name=subscription,fields=record_info(fields,subscription),keys=[id,whom,who]}
     ]}.
 
 subscribe(Who, Whom) -> kvs:put(#subscription{key={Who,Whom},who = Who, whom = Whom}).
@@ -17,7 +15,6 @@ unsubscribe(Who, Whom) ->
         true  -> kvs:delete(subscription, {Who, Whom});
         false -> skip end.
 
-subscriptions(#user{username = UId}) -> subscriptions(UId);
 subscriptions(UId) -> kvs:index(subscription, who, UId).
 subscribed(Who) -> kvs:index(subscription, whom, Who).
 subscribed(Who, Whom) ->

+ 2 - 7
src/kvs_sup.erl

@@ -1,11 +1,6 @@
 -module(kvs_sup).
 -behaviour(supervisor).
--export([start_link/0]).
--export([init/1]).
--define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+-export([init/1, start_link/0]).
 
 start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-init([]) ->
-
-    {ok, { {one_for_one, 5, 10}, []} }.
+init([])     -> {ok, { {one_for_one, 5, 10}, []} }.

+ 0 - 1
src/kvs_user.erl

@@ -2,7 +2,6 @@
 -copyright('Synrc Research Center s.r.o.').
 -include("user.hrl").
 -include("group.hrl").
--include("config.hrl").
 -include("metainfo.hrl").
 -compile(export_all).
 

+ 4 - 0
sys.config

@@ -0,0 +1,4 @@
+[
+ {kvs, [{dba,store_mnesia},
+        {schema, [kvs_user, kvs_acl, kvs_feed, kvs_subscription ]} ]}
+].