1 // this rebuilds supplementary tables in SQLite mail database.
2 // it parses the messages, extract mime parts, and populates
3 // "headers", "content", and "attaches" tables.
4 // those tables are required for the main program to work properly,
5 // but they can be dropped and recreated at any time.
6 module zsq_show_threads_slow
is aliced
;
20 // ////////////////////////////////////////////////////////////////////////// //
21 void main (string
[] args
) {
22 // here, i don't have any threads at all
23 if (sqlite3_config(SQLITE_CONFIG_SINGLETHREAD
) != SQLITE_OK
) throw new Exception("cannot switch SQLite to multi-threaded mode");
25 writeln("opening message support db...");
26 auto db = chiroOpenSupportDB();
28 string tagname
= "/dmars_ng/general";
30 Timer ctm
= Timer(true);
32 void createMsgTempTable (const(char)[] tagname
) {
34 foreach (auto trow
; db.statement(`SELECT uid AS tagid FROM tagnames WHERE tag=:tagname LIMIT 1`).bindText(":tagname", tagname
, transient
:false).range
) {
35 tagid
= trow
.tagid
!uint;
39 CREATE TEMP TABLE tempmsglist (
40 uid INTEGER PRIMARY KEY
46 INSERT INTO tempmsglist
47 SELECT uid AS uid, parent AS parent, time AS time
49 WHERE tagid=:tagid AND appearance <> -1
50 ;`).bind(":tagid", tagid
).doAll();
53 CREATE INDEX tempmsglist_parent_time ON tempmsglist(parent, time);
57 void dropMsgTempTable () {
58 db.execute(`DROP TABLE IF EXISTS tempmsglist;`);
61 writeln("collecting messages...");
63 createMsgTempTable(tagname
);
65 writeln("preliminary filtering time: ", ctm
);
68 CREATE TEMP TABLE treepane (
75 auto selMsgs
= db.persistentStatement(`
77 WITH tree(uid, parent, level, time, path) AS (
78 WITH RECURSIVE fulltree(uid, parent, level, time, path) AS (
79 SELECT tm.uid AS uid, tm.parent AS parent, 1 AS level, tm.time AS time, tm.time||'' AS path
83 SELECT t.uid AS uid, t.parent AS parent, ft.level+1 AS level, t.time AS time, ft.path||'|'||t.time AS path
84 FROM tempmsglist t, fulltree ft
87 SELECT * FROM fulltree
91 , tree.parent AS parent
93 --, datetime(tree.time, 'unixepoch') AS time
105 foreach (auto row
; db.statement(`SELECT max(rowid) AS ncount FROM treepane;`).range
) ncount
= row
.ncount
!uint;
106 writeln("collect time (", ncount
, " messages): ", ctm
);
109 writeln("closing the db");