show and save attaches
[chiroptera.git] / sqbase_experiment / zsq_90_relink_all_threads.d
blobc40003da2b08fe5286911c2c4797f68a1ee8aea6
1 /* E-Mail Client
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // this rebuilds supplementary tables in SQLite mail database.
18 // it parses the messages, extract mime parts, and populates
19 // "headers", "content", and "attaches" tables.
20 // those tables are required for the main program to work properly,
21 // but they can be dropped and recreated at any time.
22 module zsq_relink_all_threads is aliced;
24 import iv.encoding;
25 import iv.sq3;
26 import iv.strex;
27 import iv.timer;
28 import iv.vfs;
29 import iv.vfs.io;
31 import chibackend;
34 // ////////////////////////////////////////////////////////////////////////// //
35 void main (string[] args) {
36 ChiroTimerEnabled = true;
37 chiroParseCommonCLIArgs(args);
39 // here, i don't have any threads at all
40 //if (sqlite3_config(SQLITE_CONFIG_SINGLETHREAD) != SQLITE_OK) throw new Exception("cannot switch SQLite to multi-threaded mode");
42 writeln("opening message support db (compression level ", ChiroCompressionLevel, ")...");
43 chiroOpenViewDB();
45 if (args.length < 2) {
46 writeln("linking threads...");
47 chiroSupportRelinkAllThreads();
48 } else {
49 dbView.execute(`
50 CREATE TEMP TABLE timing (
51 tagid INTEGER PRIMARY KEY
52 , micro INTEGER
53 , relink INTEGER
54 , tagname TEXT
56 ;`);
57 auto stInsTiming = dbView.persistentStatement(`INSERT INTO timing (tagid, micro, relink, tagname) VALUES(:tagid, :micro, :relink, :tagname);`);
58 uint count = 0;
59 Timer ctm = Timer(true);
60 foreach (auto row; dbView.statement(`SELECT tag AS tagname, tagid AS tagid, threading AS relink FROM tagnames ORDER BY tagid;`).range) {
61 ++count;
62 //write("relinking '", row.tagname!SQ3Text, "' ... ");
63 Timer xtm = Timer(true);
64 chiroSupportRelinkTagThreads(row.tagid!uint);
65 xtm.stop;
66 //writeln(xtm);
67 stInsTiming
68 .bind(":tagid", row.tagid!uint)
69 .bind(":micro", xtm.micro)
70 .bind(":relink", row.relink!uint)
71 .bindConstText(":tagname", row.tagname!SQ3Text)
72 .doAll();
74 ctm.stop;
75 writeln(count, " threads relink time: ", ctm);
76 foreach (auto row; dbView.statement(`SELECT avg(micro) AS micro FROM timing;`).range) {
77 ctm.micro = row.micro!uint;
78 writeln("average time: ", ctm);
80 foreach (auto row; dbView.statement(`SELECT min(micro) AS micro FROM timing;`).range) {
81 ctm.micro = row.micro!uint;
82 writeln("minimum time: ", ctm);
84 foreach (auto row; dbView.statement(`SELECT max(micro) AS micro FROM timing;`).range) {
85 ctm.micro = row.micro!uint;
86 writeln("maximum time: ", ctm);
88 foreach (auto row; dbView.statement(`SELECT tagid AS tagid, micro AS micro, tagname AS tagname, relink AS relink FROM timing ORDER BY micro;`).range) {
89 uint total = 0;
90 foreach (auto trow; dbView.statement(`SELECT count(uid) AS total FROM threads WHERE tagid=:tagid;`).bind(":tagid", row.tagid!uint).range) total = trow.total!uint;
91 ctm.micro = row.micro!uint;
92 writefln("%5s:(%s): %s -- %s", total, (row.relink!uint ? "relink" : "clear "), row.tagname!SQ3Text, ctm);
96 uint ttotal = 0;
97 foreach (auto row; dbView.statement("SELECT count(*) AS total FROM threads WHERE EXISTS(SELECT threading FROM tagnames WHERE tagnames.tagid=threads.tagid AND threading=1);").range) {
98 ttotal = row.total!uint;
101 if (ttotal == 0) { writeln("WUTAFUCK!?"); ttotal = 1; }
103 foreach (auto row; dbView.statement("SELECT count(*) AS parented FROM threads WHERE parent<>0;").range) {
104 writeln(row.parented!uint, " of ", ttotal, " messages with parents found (", row.parented!uint*100/ttotal, "%).");
107 dbView.close();