From: Greg Burri Date: Sun, 1 Jun 2008 21:55:17 +0000 (+0000) Subject: MOD définition des dossiers temporaire lors d'operation sur la BD (voir si c'est... X-Git-Tag: 1.0.1^2~28 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=1c4816456885b17fab26cd8a8131a0f0569fbca7;p=euphorik.git MOD définition des dossiers temporaire lors d'operation sur la BD (voir si c'est obligatoire pour toutes les requêtes) --- diff --git a/modules/erl/euphorik_bd.erl b/modules/erl/euphorik_bd.erl index 07455d8..93cb835 100755 --- a/modules/erl/euphorik_bd.erl +++ b/modules/erl/euphorik_bd.erl @@ -90,7 +90,7 @@ % utiles : resultat_transaction/1 ]). --import(qlc, [e/1, e/2, q/1, cursor/1]). +-import(qlc, [e/2, q/1, cursor/2]). -include("../include/euphorik_bd.hrl"). -include("../include/euphorik_defines.hrl"). -include_lib("stdlib/include/qlc.hrl"). @@ -311,7 +311,8 @@ print_users(N) -> 9, q([E || E <- mnesia:table(user)]), [{order, descending}] - ) + ), + [{tmpdir, ?KEY_SORT_TEMP_DIR}] ), Users = qlc:next_answers(C, N), lists:foreach( @@ -364,7 +365,7 @@ print_user(Id) when is_integer(Id) -> user_by_cookie(Cookie) -> resultat_transaction(mnesia:transaction( fun() -> - case e(q([E || E <- mnesia:table(user), E#user.cookie =:= Cookie])) of + case e(q([E || E <- mnesia:table(user), E#user.cookie =:= Cookie]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [User] -> {ok, User}; _ -> erreur end @@ -375,7 +376,7 @@ user_by_cookie(Cookie) -> user_by_id(ID) -> resultat_transaction(mnesia:transaction( fun() -> - case e(q([E || E <- mnesia:table(user), E#user.id =:= ID])) of + case e(q([E || E <- mnesia:table(user), E#user.id =:= ID]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [User] -> {ok, User}; _ -> erreur end @@ -386,7 +387,7 @@ user_by_id(ID) -> user_by_login(Login) -> resultat_transaction(mnesia:transaction( fun() -> - Users = e(q([E || E <- mnesia:table(user), E#user.login =:= Login])), + Users = e(q([E || E <- mnesia:table(user), E#user.login =:= Login]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]), case Users of [User] -> {ok, User}; _ -> erreur @@ -398,7 +399,7 @@ user_by_login(Login) -> toggle_ek_master(User_id) -> resultat_transaction(mnesia:transaction( fun() -> - Users = e(q([E || E <- mnesia:table(user), E#user.id =:= User_id])), + Users = e(q([E || E <- mnesia:table(user), E#user.id =:= User_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]), case Users of [User] -> mnesia:write(User#user{ek_master = not User#user.ek_master}); @@ -421,7 +422,7 @@ css_from_user_cookie(Cookie) -> user_by_login_password(Login, Password) -> resultat_transaction(mnesia:transaction( fun() -> - case e(q([E || E <- mnesia:table(user), E#user.login =:= Login, E#user.password =:= Password])) of + case e(q([E || E <- mnesia:table(user), E#user.login =:= Login, E#user.password =:= Password]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [User | _] -> {ok, User}; _ -> erreur end @@ -433,7 +434,7 @@ user_by_login_password(Login, Password) -> user_by_mess(Id) -> resultat_transaction(mnesia:transaction( fun() -> - case e(q([U || U <- mnesia:table(user), M <- mnesia:table(minichat), M#minichat.id =:= Id, M#minichat.auteur_id =:= U#user.id])) of + case e(q([U || U <- mnesia:table(user), M <- mnesia:table(minichat), M#minichat.id =:= Id, M#minichat.auteur_id =:= U#user.id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [User | _] -> {ok, User}; _ -> erreur end @@ -446,9 +447,9 @@ user_by_mess(Id) -> nouveau_message(Mess, Auteur_id, Repond_A) -> % regarde si les id 'Repond_A' existent F = fun() -> - Nb_id_trouve = length(e(q([E#minichat.id || E <- mnesia:table(minichat), lists:member(E#minichat.id, Repond_A)]))), + Nb_id_trouve = length(e(q([E#minichat.id || E <- mnesia:table(minichat), lists:member(E#minichat.id, Repond_A)]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])), % est-ce que l'auteur existe ? - Auteur = case e(q([E || E <- mnesia:table(user), E#user.id =:= Auteur_id])) of + Auteur = case e(q([E || E <- mnesia:table(user), E#user.id =:= Auteur_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [A] -> A; _ -> {erreur, "L'auteur du message est introuvable"} end, @@ -518,7 +519,8 @@ messages(N, P) -> 2, q([E#minichat{contenu = contenu_message(E)} || E <- mnesia:table(minichat)]), [{order, descending}] - ) + ), + [{tmpdir, ?KEY_SORT_TEMP_DIR}] ), if P > 1 -> qlc:next_answers(C, N * (P - 1)); true -> ok @@ -569,7 +571,7 @@ messages_by_ids(Ids) -> 2, q([E || E <- mnesia:table(minichat), lists:any(fun(Id) -> Id =:= E#minichat.id end, Ids)]), [{order, ascending}] - )) + ),[{tmpdir, ?KEY_SORT_TEMP_DIR}]) end )). @@ -578,14 +580,14 @@ messages_by_ids(Ids) -> % TODO : ya pas plus simple ? message_existe(Id) -> resultat_transaction(mnesia:transaction(fun() -> - length(e(q([E#minichat.id || E <- mnesia:table(minichat), E#minichat.id =:= Id]))) =:= 1 + length(e(q([E#minichat.id || E <- mnesia:table(minichat), E#minichat.id =:= Id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}])) =:= 1 end)). % Renvoie les reponses (utilisé normalement uniquement pendant le debug). reponses() -> F = fun() -> - e(q([E || E <- mnesia:table(reponse_minichat)])) + e(q([E || E <- mnesia:table(reponse_minichat)]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) end, resultat_transaction(mnesia:transaction(F)). @@ -598,7 +600,7 @@ repond_a(M_id) -> [M || E <- mnesia:table(reponse_minichat), M <- mnesia:table(minichat), E#reponse_minichat.repondant =:= M_id, - M#minichat.id =:= E#reponse_minichat.cible])) + M#minichat.id =:= E#reponse_minichat.cible]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) end )). @@ -610,7 +612,7 @@ est_une_reponse_a_user(Id_user, Id_mess) -> e(q([ M#minichat.auteur_id || M <- mnesia:table(minichat), R <- mnesia:table(reponse_minichat), M#minichat.auteur_id =:= Id_user, M#minichat.id =:= R#reponse_minichat.cible, R#reponse_minichat.repondant =:= Id_mess - ]), [{unique_all, true}]) + ]), [{unique_all, true}, {tmpdir, ?KEY_SORT_TEMP_DIR}]) end ) of {atomic, [_]} -> true; @@ -625,7 +627,7 @@ a_repondu_a_message(Id_user, Id_mess) -> e(q([ M#minichat.auteur_id || M <- mnesia:table(minichat), R <- mnesia:table(reponse_minichat), R#reponse_minichat.cible =:= Id_mess, R#reponse_minichat.repondant =:= M#minichat.id, M#minichat.auteur_id =:= Id_user - ]), [{unique_all, true}]) + ]), [{unique_all, true}, {tmpdir, ?KEY_SORT_TEMP_DIR}]) end ) of {atomic, [_]} -> true; @@ -637,7 +639,7 @@ a_repondu_a_message(Id_user, Id_mess) -> possede_message(Id_user, Id_mess) -> case mnesia:transaction( fun() -> - e(q([E#minichat.auteur_id || E <- mnesia:table(minichat), E#minichat.id =:= Id_mess])) + e(q([E#minichat.auteur_id || E <- mnesia:table(minichat), E#minichat.id =:= Id_mess]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) end ) of {atomic, [Id_user | []]} -> true; @@ -656,11 +658,11 @@ list_ban() -> { IP#ip_table.ip, delta_date_minute(date_plus_minutes(IP#ip_table.ban, IP#ip_table.ban_duration), Now), - e(q([{U#user.pseudo, U#user.login} || U <- mnesia:table(user), U#user.last_ip =:= IP#ip_table.ip])) + e(q([{U#user.pseudo, U#user.login} || U <- mnesia:table(user), U#user.last_ip =:= IP#ip_table.ip]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) } || IP <- mnesia:table(ip_table), if IP#ip_table.ban =:= undefined -> false; true -> date_plus_minutes(IP#ip_table.ban, IP#ip_table.ban_duration) > Now end - ]))) + ])), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) end )). @@ -695,7 +697,7 @@ est_banni(User_id) -> U#user.id =:= User_id, IP <- mnesia:table(ip_table), IP#ip_table.ip =:= U#user.last_ip - ])) of + ]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [{Ban, Ban_duration}] -> Echeance = date_plus_minutes(Ban, Ban_duration), Now = now(), @@ -726,7 +728,7 @@ date_plus_minutes(Ban, Ban_duration) -> can_register(IP) -> resultat_transaction(mnesia:transaction( fun() -> - case e(q([I || I <- mnesia:table(ip_table), I#ip_table.ip =:= IP])) of + case e(q([I || I <- mnesia:table(ip_table), I#ip_table.ip =:= IP]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [] -> mnesia:write(#ip_table{ip = IP, date_last_try_register = now()}), true; @@ -751,7 +753,7 @@ can_register(IP) -> trolls() -> resultat_transaction(mnesia:transaction( fun() -> - e(qlc:keysort(2, q([T || T <- mnesia:table(troll)]))) + e(qlc:keysort(2, q([T || T <- mnesia:table(troll)])), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) end )). @@ -760,7 +762,7 @@ trolls() -> trolls(Last_id) -> resultat_transaction(mnesia:transaction( fun() -> - e(qlc:keysort(2, q([T || T <- mnesia:table(troll), T#troll.id > Last_id, T#troll.date_post =:= undefined]))) + e(qlc:keysort(2, q([T || T <- mnesia:table(troll), T#troll.id > Last_id, T#troll.date_post =:= undefined])), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) end )). @@ -780,13 +782,13 @@ put_troll(User_id, Content) -> E#troll.id_user =:= User_id, E#troll.date_post =:= undefined ] - ))), + ), [{tmpdir, ?KEY_SORT_TEMP_DIR}])), Nb_troll_poste_total = length(e(q( [ E#troll.id || E <- mnesia:table(troll), E#troll.date_post =:= undefined ] - ))), + ), [{tmpdir, ?KEY_SORT_TEMP_DIR}])), User = user_by_id(User_id), case User of {ok, _} -> @@ -836,7 +838,7 @@ del_troll(Troll_id) -> troll_by_id(Troll_id) -> resultat_transaction(mnesia:transaction( fun() -> - case e(q([T || T <- mnesia:table(troll), T#troll.id =:= Troll_id])) of + case e(q([T || T <- mnesia:table(troll), T#troll.id =:= Troll_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [T] -> {ok, T}; _ -> erreur @@ -851,7 +853,7 @@ current_troll() -> resultat_transaction(mnesia:transaction( fun() -> % TODO : ya pas moyen de désigner le champs plutot qu'avec un nombre pour le tri ? - C = cursor(qlc:keysort(5, q([T || T <- mnesia:table(troll), T#troll.date_post =/= undefined]), [{order, descending}])), + C = cursor(qlc:keysort(5, q([T || T <- mnesia:table(troll), T#troll.date_post =/= undefined]), [{order, descending}]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]), R = case qlc:next_answers(C, 1) of [T] -> T; _ -> aucun @@ -871,7 +873,7 @@ elire_troll() -> random:seed(A1, A2, A3), mnesia:transaction( fun() -> - case e(q([T || T <- mnesia:table(troll), T#troll.date_post =:= undefined])) of + case e(q([T || T <- mnesia:table(troll), T#troll.date_post =:= undefined]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [] -> plus_de_trolls; Trolls -> @@ -889,7 +891,7 @@ elire_troll() -> message_id_associe(Troll_id) -> resultat_transaction(mnesia:transaction( fun() -> - case e(q([M#minichat.id || M <- mnesia:table(minichat), M#minichat.troll_id =:= Troll_id])) of + case e(q([M#minichat.id || M <- mnesia:table(minichat), M#minichat.troll_id =:= Troll_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of [Id] -> Id; _ -> undefined end diff --git a/modules/erl/euphorik_daemon.erl b/modules/erl/euphorik_daemon.erl index 51f224e..be3b39c 100755 --- a/modules/erl/euphorik_daemon.erl +++ b/modules/erl/euphorik_daemon.erl @@ -28,9 +28,7 @@ % Démarre le démon -start(_A) -> - % dossier utilisé lors de gros trie par qlc, voir qlc:keysort() - file:set_cwd("/tmp"), +start(_A) -> loop(). diff --git a/modules/erl/euphorik_minichat_conversation.erl b/modules/erl/euphorik_minichat_conversation.erl index 2db3586..06fad7f 100755 --- a/modules/erl/euphorik_minichat_conversation.erl +++ b/modules/erl/euphorik_minichat_conversation.erl @@ -30,11 +30,12 @@ -export([ conversations/4 ]). --include("euphorik_bd.hrl"). +-include("../include/euphorik_bd.hrl"). +-include("../include/euphorik_defines.hrl"). -include_lib("stdlib/include/qlc.hrl"). -import(lists, [reverse/1, any/2, map/2, sublist/3, filter/2]). -import(euphorik_bd, [resultat_transaction/1]). --import(qlc, [e/1, q/1, keysort/3]). +-import(qlc, [e/2, q/1, keysort/3]). -import(mnesia, [table/1, transaction/1]). @@ -100,7 +101,7 @@ mise_en_forme_conversation(Messages) -> conversations_detailees(Racines, N, D, P) -> Conversations = map(fun({Racine, P_conv, Dernier}) -> conversation(Racine, N, Dernier, P_conv) end, Racines), Conversation_principale = resultat_transaction(transaction(fun() -> - Curseur = qlc:cursor(q([E#minichat.id || E <- qlc:sort(table(minichat), [{order, descending}])])), + Curseur = qlc:cursor(q([E#minichat.id || E <- qlc:sort(table(minichat), [{order, descending}])]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]), {CP, Plus} = conversation_principale(Curseur, Conversations, N, P), qlc:delete_cursor(Curseur), {[M || M <- CP, M > D], Plus} % filtre en fonction de D @@ -205,7 +206,8 @@ enfants(M) -> qlc:sort( q([E#reponse_minichat.repondant || E <- table(reponse_minichat), E#reponse_minichat.cible =:= M]), [{order, ascending}] - ) + ), + [{tmpdir, ?KEY_SORT_TEMP_DIR}] ) end)). @@ -219,7 +221,8 @@ parents(M) -> qlc:sort( q([E#reponse_minichat.cible || E <- table(reponse_minichat), E#reponse_minichat.repondant =:= M]), [{order, ascending}] - ) + ), + [{tmpdir, ?KEY_SORT_TEMP_DIR}] ) end)). diff --git a/modules/include/euphorik_defines.hrl b/modules/include/euphorik_defines.hrl index 9fe5f8e..c0791b5 100755 --- a/modules/include/euphorik_defines.hrl +++ b/modules/include/euphorik_defines.hrl @@ -45,3 +45,7 @@ % Le jour ainsi que l'heure à laquelle est élu un nouveau troll (lundi à 3 heure du mat) -define(JOUR_ELECTION_TROLL, 1). % 1 = lundi -define(HEURE_ELECTION_TROLL, 3). % 3 heure du matin + + +% Le dossier utilisé pour le trie (qlc:keysort()) +-define(KEY_SORT_TEMP_DIR, "/tmp").