From 08193845f5b45402b85977911dbd0693a4d183de Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Sun, 1 Jun 2008 17:24:04 +0000 Subject: [PATCH] =?utf8?q?FIX=20optimisation=20de=20certaine=20requ=C3=AAt?= =?utf8?q?e=20:=20il=20faut=20trier=20apr=C3=A8s=20pas=20avant,=20banane?= =?utf8?q?=20!=20MOD=20quelques=20mini=20modifs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- css/1/euphorik.css | 3 +- js/pageMinichat.js | 7 +-- modules/erl/euphorik_bd.erl | 63 ++++++++++++------- .../erl/euphorik_minichat_conversation.erl | 44 ++++++++----- modules/erl/euphorik_test.erl | 20 +++++- pages/about.html | 4 +- tools/mise_en_prod.rb | 4 ++ 7 files changed, 100 insertions(+), 45 deletions(-) diff --git a/css/1/euphorik.css b/css/1/euphorik.css index 3e09bc7..1fdc0f4 100755 --- a/css/1/euphorik.css +++ b/css/1/euphorik.css @@ -112,7 +112,8 @@ ul#menu { #footer { background-color: #e19671; text-align: right; - font-size: 9px + font-size: 9px; + padding: 2px } #footer a img{ border-style: none; diff --git a/js/pageMinichat.js b/js/pageMinichat.js index 356956c..adf5c5a 100755 --- a/js/pageMinichat.js +++ b/js/pageMinichat.js @@ -63,7 +63,6 @@ PageMinichat.prototype.charger = function() this.util.outilsBan = $( '' + '

' + - '

' + 'Ban de 3 jours' + 'Ban de 15min' + 'Avertissement' + @@ -920,11 +919,11 @@ Messages.prototype.rafraichirMessages = function(vider) if (vider) for (var i = 0; i < this.conversations.length; i++) this.conversations[i].idDernierMessageAffiche = 0 - + this.pageEvent.waitEvent( function() { return thisMessages.getJSONrafraichirMessages() }, function(data) - { + { if (vider) { thisMessages.viderMessages() @@ -946,7 +945,7 @@ Messages.prototype.rafraichirMessages = function(vider) $("#trollCourant .troll a[@rel*=lightbox]").lightBox() break - case "new_messages" : + case "new_messages" : // ajoute les messages reçus à leur conversation respective for (var numConv = 0; numConv < data["conversations"].length; numConv++) { diff --git a/modules/erl/euphorik_bd.erl b/modules/erl/euphorik_bd.erl index 187d6ea..89c9836 100755 --- a/modules/erl/euphorik_bd.erl +++ b/modules/erl/euphorik_bd.erl @@ -57,6 +57,7 @@ messages/2, messages/3, message_by_id/1, + message_by_id_sans_transaction/1, messages_by_ids/1, message_existe/1, reponses/0, @@ -107,6 +108,7 @@ create() -> mnesia:start(), create_tables(), reset(). + create_tables() -> mnesia:create_table(counter, [ {attributes, record_info(fields, counter)}, @@ -153,7 +155,8 @@ connect(Node) -> % Efface tous les users, minichat_reponse et minichat. reset() -> - mnesia:clear_table(counter), + mnesia:clear_table(counter), + mnesia:clear_table(proprietes), mnesia:clear_table(user), mnesia:clear_table(reponse_minichat), mnesia:clear_table(minichat), @@ -304,7 +307,13 @@ update_pseudo_user(UserId, Pseudo) -> % Attention : pas d'index sur ce champs (la date) print_users(N) -> resultat_transaction(mnesia:transaction(fun() -> - C = cursor(q([E || E <- qlc:keysort(9, mnesia:table(user), [{order, descending}])])), + C = cursor( + qlc:keysort( + 9, + q([E || E <- mnesia:table(user)]), + [{order, descending}] + ) + ), Users = qlc:next_answers(C, N), lists:foreach( fun(U) -> @@ -505,12 +514,15 @@ messages(N) -> % Renvoie N messages se trouvant sur la page P -messages(N, P) -> +messages(N, P) -> F = fun() -> - C = cursor(q([ - E#minichat{contenu = contenu_message(E)} || - E <- qlc:keysort(2, mnesia:table(minichat), [{order, descending}]) - ])), + C = cursor( + qlc:keysort( + 2, + q([E#minichat{contenu = contenu_message(E)} || E <- mnesia:table(minichat)]), + [{order, descending}] + ) + ), if P > 1 -> qlc:next_answers(C, N * (P - 1)); true -> ok end, @@ -529,20 +541,26 @@ messages(Id, N, P) -> % Renvoie {ok, #minichat} (voir #minichat de euphorik_bd.hrl) à partir de son id. message_by_id(Id) -> - case resultat_transaction(mnesia:transaction( + resultat_transaction(mnesia:transaction( fun() -> - e(q([E#minichat{contenu = contenu_message(E)} || E <- qlc:keysort(2, mnesia:table(minichat), [{order, ascending}]), Id =:= E#minichat.id])) + message_by_id_sans_transaction(Id) end - )) of - [M] -> {ok, M}; - _ -> erreur + )). +message_by_id_sans_transaction(Id) -> + case mnesia:read({minichat, Id}) of + [] -> erreur; + [M] -> + {ok, M#minichat{contenu = contenu_message(M)}} end. % Renvoie le contenu d'un message donnée, à utiliser à l'intérieur d'une transaction. % TODO : Cette fonction pourrait être remplacé par un "outer-join", est-ce possible avec qlc ? contenu_message(E) -> - lists:flatten(E#minichat.contenu ++ e(q([T#troll.content || T <- mnesia:table(troll), T#troll.id =:= E#minichat.troll_id]))). + case mnesia:read({troll, E#minichat.troll_id}) of + [] -> E#minichat.contenu; + [T] -> E#minichat.contenu ++ T#troll.content + end. % Renvoie une liste de message (voir #minichat de euphorik_bd.hrl) à partir d'une liste d'id (Ids). @@ -550,8 +568,11 @@ messages_by_ids(Ids) -> resultat_transaction(mnesia:transaction( fun() -> % TODO : optimisations ? serait-ce du O(n) ? - Query = q([E || E <- qlc:keysort(2, mnesia:table(minichat), [{order, ascending}]), lists:any(fun(Id) -> Id =:= E#minichat.id end, Ids)]), - e(Query) + e(qlc:keysort( + 2, + q([E || E <- mnesia:table(minichat), lists:any(fun(Id) -> Id =:= E#minichat.id end, Ids)]), + [{order, ascending}] + )) end )). @@ -634,15 +655,15 @@ list_ban() -> resultat_transaction(mnesia:transaction( fun() -> Now = now(), - e(q([ + e(qlc:keysort(1, q([ { 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])) } || - IP <- qlc:keysort(2, mnesia:table(ip_table)), + 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 - ])) + ]))) end )). @@ -733,7 +754,7 @@ can_register(IP) -> trolls() -> resultat_transaction(mnesia:transaction( fun() -> - e(q([T || T <- qlc:keysort(2, mnesia:table(troll))])) + e(qlc:keysort(2, q([T || T <- mnesia:table(troll)]))) end )). @@ -742,7 +763,7 @@ trolls() -> trolls(Last_id) -> resultat_transaction(mnesia:transaction( fun() -> - e(q([T || T <- qlc:keysort(2, 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]))) end )). @@ -833,7 +854,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(q([T || T <- qlc:keysort(5, mnesia:table(troll), [{order, descending}]), T#troll.date_post =/= undefined])), + C = cursor(qlc:keysort(5, q([T || T <- mnesia:table(troll), T#troll.date_post =/= undefined]), [{order, descending}])), R = case qlc:next_answers(C, 1) of [T] -> T; _ -> aucun diff --git a/modules/erl/euphorik_minichat_conversation.erl b/modules/erl/euphorik_minichat_conversation.erl index 3c88caa..2db3586 100755 --- a/modules/erl/euphorik_minichat_conversation.erl +++ b/modules/erl/euphorik_minichat_conversation.erl @@ -75,19 +75,23 @@ mise_en_forme_conversations([{Principale, Plus_principale} | Conversations]) -> % Ajoute les parents de chaque message. % @spec mise_en_forme_conversation([integer()]) -> [{integer(), [integer()]}] mise_en_forme_conversation(Messages) -> - lists:foldr( - fun(Id, Acc) -> - case euphorik_bd:message_by_id(Id) of - {ok, Message} -> - [{Message, parents(Id)} | Acc]; - _ -> - Acc - end - end, - [], - Messages - ). - + resultat_transaction(mnesia:transaction( + fun() -> + lists:foldr( + fun(Id, Acc) -> + case euphorik_bd:message_by_id_sans_transaction(Id) of + {ok, Message} -> + [{Message, parents(Id)} | Acc]; + _ -> + Acc + end + end, + [], + Messages + ) + end + )). + % Renvoie une liste de conversations, le première élément correspond à la conversation principale. % Les autres éléments sont des tuples {C, Cn, X}, voir conversation/4 pour plus d'infos. @@ -197,7 +201,12 @@ conversation(Messages, [], X) -> % @spec enfants(integer()) -> [integer()] enfants(M) -> resultat_transaction(transaction(fun() -> - e(q([E#reponse_minichat.repondant || E <- qlc:sort(table(reponse_minichat), [{order, ascending}]), E#reponse_minichat.cible =:= M])) + e( + qlc:sort( + q([E#reponse_minichat.repondant || E <- table(reponse_minichat), E#reponse_minichat.cible =:= M]), + [{order, ascending}] + ) + ) end)). @@ -206,7 +215,12 @@ enfants(M) -> % @spec parents(integer()) -> [integer()] parents(M) -> resultat_transaction(transaction(fun() -> - e(q([E#reponse_minichat.cible || E <- keysort(1, table(reponse_minichat), [{order, ascending}]), E#reponse_minichat.repondant =:= M])) + e( + qlc:sort( + q([E#reponse_minichat.cible || E <- table(reponse_minichat), E#reponse_minichat.repondant =:= M]), + [{order, ascending}] + ) + ) end)). diff --git a/modules/erl/euphorik_test.erl b/modules/erl/euphorik_test.erl index d5c83c3..c602292 100644 --- a/modules/erl/euphorik_test.erl +++ b/modules/erl/euphorik_test.erl @@ -1,11 +1,27 @@ % coding: utf-8 +% Copyright 2008 Grégory Burri +% +% This file is part of Euphorik. +% +% Euphorik is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Euphorik is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Euphorik. If not, see . +% % Module de test de euphorik. % Crée un certain nombre d'utilisateur et post des messages aléatoire. -module(euphorik_test). --compile(export_all). - +-export([start/1, stop/1]). -include("../include/euphorik_bd.hrl"). diff --git a/pages/about.html b/pages/about.html index b19724c..a30e345 100644 --- a/pages/about.html +++ b/pages/about.html @@ -1,7 +1,7 @@

euphorik.ch

-

Version : 0.9 (beta)

+

Version : 1.0.0

Auteur : Pifou

FAQ

@@ -19,7 +19,7 @@

Quels-sont les navigateurs supportés ?

-

Le site a été testé sous "Firefox 2 et 3", "Safari 3", "Opera 9". +

Le site a été testé sous "Firefox 2 et 3", "Safari 3" et "Opera 9". Il est fortement déconseillé d'utiliser Microsoft Internet Explorer pour des raisons d'incompatibilités.

diff --git a/tools/mise_en_prod.rb b/tools/mise_en_prod.rb index 23c62cb..ae0bb8f 100755 --- a/tools/mise_en_prod.rb +++ b/tools/mise_en_prod.rb @@ -33,6 +33,10 @@ end # Compilation de la partie serveur Dir.chdir('../modules') puts `make` +if $?.exitstatus != 0 + puts "Echec de compilation de la partie serveuse" + exit 1 +end Dir.chdir('..') # création du repertoire BD -- 2.45.2