FIX optimisation de certaine requête : il faut trier après pas avant, banane !
authorGreg Burri <greg.burri@gmail.com>
Sun, 1 Jun 2008 17:24:04 +0000 (17:24 +0000)
committerGreg Burri <greg.burri@gmail.com>
Sun, 1 Jun 2008 17:24:04 +0000 (17:24 +0000)
MOD quelques mini modifs

css/1/euphorik.css
js/pageMinichat.js
modules/erl/euphorik_bd.erl
modules/erl/euphorik_minichat_conversation.erl
modules/erl/euphorik_test.erl
pages/about.html
tools/mise_en_prod.rb

index 3e09bc7..1fdc0f4 100755 (executable)
@@ -112,7 +112,8 @@ ul#menu {
 #footer {
        background-color: #e19671;
        text-align: right;
 #footer {
        background-color: #e19671;
        text-align: right;
-       font-size: 9px
+       font-size: 9px;
+       padding: 2px
 }
 #footer a img{
        border-style: none;
 }
 #footer a img{
        border-style: none;
index 356956c..adf5c5a 100755 (executable)
@@ -63,7 +63,6 @@ PageMinichat.prototype.charger = function()
       this.util.outilsBan = $(
          '<span id="outilsBan">' +
          '<form action=""><p><input id="raison" name="raison" type="text" size="10" maxlength="200"></input></p></form>' +
       this.util.outilsBan = $(
          '<span id="outilsBan">' +
          '<form action=""><p><input id="raison" name="raison" type="text" size="10" maxlength="200"></input></p></form>' +
-         '<form action=""><p><input id="raison" name="raison" type="text" size="10" maxlength="200"></input></p></form>' +
          '<img id="ban" src="img/ban.gif" alt="Ban de 3 jours" />' +
          '<img id="kick" src="img/kick.gif" alt="Ban de 15min" />' +
          '<img id="slap" src="img/slap.gif" alt="Avertissement" />' +
          '<img id="ban" src="img/ban.gif" alt="Ban de 3 jours" />' +
          '<img id="kick" src="img/kick.gif" alt="Ban de 15min" />' +
          '<img id="slap" src="img/slap.gif" alt="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
    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)
    this.pageEvent.waitEvent(
       function() { return thisMessages.getJSONrafraichirMessages() },
       function(data)
-      {
+      {   
          if (vider)
          {
             thisMessages.viderMessages()
          if (vider)
          {
             thisMessages.viderMessages()
@@ -946,7 +945,7 @@ Messages.prototype.rafraichirMessages = function(vider)
                $("#trollCourant .troll a[@rel*=lightbox]").lightBox()
                break
                
                $("#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++)
                {
                // ajoute les messages reçus à leur conversation respective
                for (var numConv = 0; numConv < data["conversations"].length; numConv++)
                {
index 187d6ea..89c9836 100755 (executable)
@@ -57,6 +57,7 @@
    messages/2,\r
    messages/3,
    message_by_id/1,
    messages/2,\r
    messages/3,
    message_by_id/1,
+   message_by_id_sans_transaction/1,
    messages_by_ids/1,
    message_existe/1,
    reponses/0,
    messages_by_ids/1,
    message_existe/1,
    reponses/0,
@@ -107,6 +108,7 @@ create() ->
    mnesia:start(),
    create_tables(),
    reset().
    mnesia:start(),
    create_tables(),
    reset().
+   
 create_tables() ->
    mnesia:create_table(counter, [
       {attributes, record_info(fields, counter)},
 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.\r
 reset() ->\r
 
 % Efface tous les users, minichat_reponse et minichat.\r
 reset() ->\r
-   mnesia:clear_table(counter),\r
+   mnesia:clear_table(counter),
+   mnesia:clear_table(proprietes),\r
    mnesia:clear_table(user),\r
    mnesia:clear_table(reponse_minichat),\r
    mnesia:clear_table(minichat),
    mnesia:clear_table(user),\r
    mnesia:clear_table(reponse_minichat),\r
    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() ->
 % 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) ->
       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
 
 
 % Renvoie N messages se trouvant sur la page P
-messages(N, P) ->  
+messages(N, P) ->
    F = fun() ->
    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,
       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) ->
    
 % 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() ->
       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
       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) ->
    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).
   
 
 % 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) ?
    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
    )).
    
       end
    )).
    
@@ -634,15 +655,15 @@ list_ban() ->
    resultat_transaction(mnesia:transaction(
       fun() ->
          Now = now(),
    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#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
             if IP#ip_table.ban =:= undefined -> false; true -> date_plus_minutes(IP#ip_table.ban, IP#ip_table.ban_duration) > Now end
-         ]))
+         ])))
       end
    )).
 
       end
    )).
 
@@ -733,7 +754,7 @@ can_register(IP) ->
 trolls() ->
    resultat_transaction(mnesia:transaction(
       fun() ->
 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
    )).
    
       end
    )).
    
@@ -742,7 +763,7 @@ trolls() ->
 trolls(Last_id) ->
    resultat_transaction(mnesia:transaction(
       fun() ->
 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
    )).
    
       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 ?
    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
          R = case qlc:next_answers(C, 1) of
             [T] -> T;
             _ -> aucun
index 3c88caa..2db3586 100755 (executable)
@@ -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) ->
 % 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.
    
 % 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() ->
 % @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)).
    
    
    end)).
    
    
@@ -206,7 +215,12 @@ enfants(M) ->
 % @spec parents(integer()) -> [integer()]
 parents(M) ->
    resultat_transaction(transaction(fun() ->
 % @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)).
    
 
    end)).
    
 
index d5c83c3..c602292 100644 (file)
@@ -1,11 +1,27 @@
 % coding: utf-8
 % 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 <http://www.gnu.org/licenses/>.
+%
 % Module de test de euphorik.
 % Crée un certain nombre d'utilisateur et post des messages aléatoire.
 
 
 -module(euphorik_test).
 % 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").
 
 
 -include("../include/euphorik_bd.hrl").
 
 
index b19724c..a30e345 100644 (file)
@@ -1,7 +1,7 @@
 <!-- encoding: utf-8 -->\r
 \r
 <h1>euphorik.ch</h1>\r
 <!-- encoding: utf-8 -->\r
 \r
 <h1>euphorik.ch</h1>\r
-<p>Version : 0.9 (beta)</p>\r
+<p>Version : 1.0.0</p>\r
 <p>Auteur : <a href="{EMAIL_LIEN}">Pifou</a></p>
 
 <h2>FAQ</h2>
 <p>Auteur : <a href="{EMAIL_LIEN}">Pifou</a></p>
 
 <h2>FAQ</h2>
@@ -19,7 +19,7 @@
 \r
 
 <h3>Quels-sont les navigateurs supportés ?</h3>
 \r
 
 <h3>Quels-sont les navigateurs supportés ?</h3>
-<p>Le site a été testé sous "Firefox 2 et 3", "Safari 3", "Opera 9".
+<p>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.</p>
 
 
 Il est fortement déconseillé d'utiliser Microsoft Internet Explorer pour des raisons d'incompatibilités.</p>
 
 
index 23c62cb..ae0bb8f 100755 (executable)
@@ -33,6 +33,10 @@ end
 # Compilation de la partie serveur
 Dir.chdir('../modules')
 puts `make`
 # 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
 Dir.chdir('..')
 
 # création du repertoire BD