receiver: better filter processing
[chiroptera.git] / sqbase_experiment / zsq_90_relink_all_threads.d
blob5aec316653d1fd20380358cfd625c968a52ce79f
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 __gshared bool wasProgress = false;
37 extern(C) int SQ3Progress (void *udata) {
38 wasProgress = true;
39 write(".");
40 return 0; // continue
44 // ////////////////////////////////////////////////////////////////////////// //
45 void main (string[] args) {
46 ChiroTimerEnabled = true;
47 chiroParseCommonCLIArgs(args);
49 MailDBPath = "_000";
51 // here, i don't have any threads at all
52 //if (sqlite3_config(SQLITE_CONFIG_SINGLETHREAD) != SQLITE_OK) throw new Exception("cannot switch SQLite to multi-threaded mode");
54 writeln("opening message support db (compression level ", ChiroCompressionLevel, ")...");
55 chiroOpenViewDB();
57 if (args.length < 2) {
58 writeln("linking threads...");
59 chiroSupportRelinkAllThreads();
60 } else {
61 dbView.execute(`
62 CREATE TEMP TABLE timing (
63 tagid INTEGER PRIMARY KEY
64 , micro INTEGER
65 , relink INTEGER
66 , tagname TEXT
68 ;`);
69 auto stInsTiming = dbView.persistentStatement(`INSERT INTO timing (tagid, micro, relink, tagname) VALUES(:tagid, :micro, :relink, :tagname);`);
70 uint count = 0;
71 sqlite3_progress_handler(dbView.getHandle, 32, &SQ3Progress);
72 Timer ctm = Timer(true);
73 foreach (auto row; dbView.statement(`SELECT tag AS tagname, tagid AS tagid, threading AS relink FROM tagnames ORDER BY tagid;`).range) {
74 ++count;
75 //write("relinking '", row.tagname!SQ3Text, "' ... ");
76 Timer xtm = Timer(true);
77 chiroSupportRelinkTagThreads(row.tagid!uint);
78 xtm.stop;
79 //writeln(xtm);
80 stInsTiming
81 .bind(":tagid", row.tagid!uint)
82 .bind(":micro", xtm.micro)
83 .bind(":relink", row.relink!uint)
84 .bindConstText(":tagname", row.tagname!SQ3Text)
85 .doAll();
87 ctm.stop;
88 if (wasProgress) writeln;
89 writeln(count, " threads relink time: ", ctm);
90 foreach (auto row; dbView.statement(`SELECT avg(micro) AS micro FROM timing;`).range) {
91 ctm.micro = row.micro!uint;
92 writeln("average time: ", ctm);
94 foreach (auto row; dbView.statement(`SELECT min(micro) AS micro FROM timing;`).range) {
95 ctm.micro = row.micro!uint;
96 writeln("minimum time: ", ctm);
98 foreach (auto row; dbView.statement(`SELECT max(micro) AS micro FROM timing;`).range) {
99 ctm.micro = row.micro!uint;
100 writeln("maximum time: ", ctm);
102 foreach (auto row; dbView.statement(`SELECT tagid AS tagid, micro AS micro, tagname AS tagname, relink AS relink FROM timing ORDER BY micro;`).range) {
103 uint total = 0;
104 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;
105 ctm.micro = row.micro!uint;
106 writefln("%5s:(%s): %s -- %s", total, (row.relink!uint ? "relink" : "clear "), row.tagname!SQ3Text, ctm);
110 uint ttotal = 0;
111 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) {
112 ttotal = row.total!uint;
115 if (ttotal == 0) { writeln("WUTAFUCK!?"); ttotal = 1; }
117 foreach (auto row; dbView.statement("SELECT count(*) AS parented FROM threads WHERE parent<>0;").range) {
118 writeln(row.parented!uint, " of ", ttotal, " messages with parents found (", row.parented!uint*100/ttotal, "%).");
121 dbView.close();