TODO * factorise paginations * new and preview using tabs What is below is just for future personal reference... http://www.ajaxchat.org/chat/ # Here is my console code to reset threads from their original mails: >> elts=Mail.find_all.select{|m|m.file and mail=TMail::Mail.parse(m.file) and reply=mail.in_reply_to and mailObject=Mail.find_by_message(reply) and mailObject.elt.id!=m.elt.parent_id}.collect{|m| {:elt=>m.elt.id, :parent=>Mail.find_by_message(TMail::Mail.parse(m.file).in_reply_to).elt.id}}; puts elts.size >> elts.each{|e|print e[:elt], ' ', e[:parent], ' '; puts Elt.update_all("parent_id='#{e[:parent]}'", "id='#{e[:elt]}'")}; puts elts.size # To get and remove duplicate messages >> messages=Mail.find_by_sql "select message from mails group by message having count(message) > 1"; puts messages.length >> messages.each{ |m| mail=Mail.find_all_by_message m.message; mail.each{|m| print m.elt.id, ' ', m.elt.subject, ' ', m.elt.children.size; puts } }; puts messages.length >> messages.each{ |m| mail=Mail.find_all_by_message m.message; mail.each_index{|i| m=mail[i]; print i, ' ', m.elt.id, ' ', m.elt.subject, ' ', m.elt.children.size; m.elt.destroy if i>0 and m.elt.children.size==0; puts } }; puts messages.length # To get all existing votes elts=Elt.find(:all, :conditions => ["body LIKE '%%+1%%' OR body LIKE '%%0%%' OR body LIKE '%%-1%%'"]); puts elts.size elts.each { |e| print '(', Regexp.last_match(1), ')' if e.body =~ /^\s*(-1|0|\+1)(\s*|$)/ }; puts; puts elts.size elts.each { |e| e.vote(Regexp.last_match(1), e.person) if e.body =~ /^\s*(-1|0|\+1)(\s*|$)/ }; puts; puts elts.size UPDATE elts SET elts_count = (SELECT COUNT(*) FROM elts e2 WHERE e2.parent_id = elts.id); # To reconstruct the nested tree set def construction(e, counter) e.lft = counter counter += 1 e.children.each { |c| counter = construction(c, counter) } e.rgt = counter counter += 1 e.save counter end e=Elt.find('ROOT') construction(e, 0) UPDATE elts SET lft = NULL, rgt = NULL; ALTER TABLE elts ADD CONSTRAINT elts_unique_lft UNIQUE (lft); ALTER TABLE elts ADD CONSTRAINT elts_unique_rgt UNIQUE (rgt); SELECT * FROM person_mails; INSERT INTO person_mails (person_id, mail_id, created_on) VALUES ('first', 'aGaGwUHxCr25c5aaVnmTrI', now()); select id from mails; select count(*) from mails; select * from people; select * from subscriptions; select * from person_mails; select distinct last_activity from elts; UPDATE elts SET last_activity = (SELECT MAX(created_on) FROM elts c WHERE elts.lft <= c.lft AND c.rgt <= elts.rgt); Processing EltController#create (for 192.168.0.254 at 2007-02-11 00:07:05) [POST] Session ID: 23a1ab5f9b11763838d64c50157610f3 Parameters: {"commit"=>"Propose!", "elt"=>{"body"=>"arg", "subject"=>"Re: Testez", "parent_id"=>"Testez"}, "submit"=>"preview", "action"=>"create", "id"=>"Testez", "controller"=>"elt"} Response body was encoded with gzip Completed in 0.05879 (17 reqs/sec) | Rendering: 0.05682 (96%) | DB: 0.00072 (1%) | 200 OK [http://leparlement.org/elt/create/Testez?submit=preview]