Fossil SCM

Add the experimental /repo_tabsize page. It does not work because it shows the sizes of tables in the checkout database in some cases. Work is needed on the underlying dbstat virtual table. We will address that in the future and come back to this branch afterwards.

drh 2015-05-07 01:56 UTC piechart
Commit ce5af0966e7965bf0df1df4d8bb124d227f13bfb
1 file changed +49
+49
--- src/stat.c
+++ src/stat.c
@@ -355,5 +355,54 @@
355355
}
356356
@ </pre>
357357
db_finalize(&q);
358358
style_footer();
359359
}
360
+
361
+/*
362
+** WEBPAGE: repo_tabsize
363
+**
364
+** Show relative sizes of tables in the repository database.
365
+*/
366
+void repo_tabsize_page(void){
367
+ Stmt q;
368
+ login_check_credentials();
369
+ int nPageTotal;
370
+ int nPageSmall;
371
+ int nPageFree;
372
+ if( !g.perm.Admin ){ login_needed(0); return; }
373
+
374
+ style_header("Repository Table Sizes");
375
+ style_adunit_config(ADUNIT_RIGHT_OK);
376
+ style_submenu_element("Stat", "Repository Stats", "stat");
377
+ style_submenu_element("URLs", "URLs and Checkouts", "urllist");
378
+ db_multi_exec(
379
+ "CREATE VIRTUAL TABLE temp.dbx USING dbstat;"
380
+ "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY, tabname TEXT)WITHOUT ROWID;"
381
+ "INSERT INTO trans(name,tabname)"
382
+ " SELECT name, tbl_name FROM %s.sqlite_master;"
383
+ "CREATE TEMP TABLE piechart(amt REAL, label TEXT);"
384
+ "INSERT INTO piechart(amt,label)"
385
+ " SELECT count(*), "
386
+ " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
387
+ " FROM dbx"
388
+ " GROUP BY 2 ORDER BY 2;",
389
+ db_name("repository")
390
+ );
391
+ nPageFree = db_int(0, "PRAGMA freelist_count");
392
+ db_multi_exec(
393
+ "INSERT INTO piechart(amt,label) VALUES(%d,'(freelist)')",
394
+ nPageFree
395
+ );
396
+ nPageTotal = db_int(0, "SELECT sum(amt) FROM piechart");
397
+ nPageSmall = db_int(0, "SELECT sum(amt) FROM piechart WHERE amt<%d",
398
+ nPageTotal/50);
399
+ db_multi_exec(
400
+ "DELETE FROM piechart WHERE amt<%d;"
401
+ "INSERT INTO piechart(amt,label) VALUES(%d,'(other)')",
402
+ nPageTotal/50, nPageSmall
403
+ );
404
+ @ <center><svg width='800' height='600'>
405
+ piechart_render(800,600);
406
+ @ </svg>
407
+ style_footer();
408
+}
360409
--- src/stat.c
+++ src/stat.c
@@ -355,5 +355,54 @@
355 }
356 @ </pre>
357 db_finalize(&q);
358 style_footer();
359 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
--- src/stat.c
+++ src/stat.c
@@ -355,5 +355,54 @@
355 }
356 @ </pre>
357 db_finalize(&q);
358 style_footer();
359 }
360
361 /*
362 ** WEBPAGE: repo_tabsize
363 **
364 ** Show relative sizes of tables in the repository database.
365 */
366 void repo_tabsize_page(void){
367 Stmt q;
368 login_check_credentials();
369 int nPageTotal;
370 int nPageSmall;
371 int nPageFree;
372 if( !g.perm.Admin ){ login_needed(0); return; }
373
374 style_header("Repository Table Sizes");
375 style_adunit_config(ADUNIT_RIGHT_OK);
376 style_submenu_element("Stat", "Repository Stats", "stat");
377 style_submenu_element("URLs", "URLs and Checkouts", "urllist");
378 db_multi_exec(
379 "CREATE VIRTUAL TABLE temp.dbx USING dbstat;"
380 "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY, tabname TEXT)WITHOUT ROWID;"
381 "INSERT INTO trans(name,tabname)"
382 " SELECT name, tbl_name FROM %s.sqlite_master;"
383 "CREATE TEMP TABLE piechart(amt REAL, label TEXT);"
384 "INSERT INTO piechart(amt,label)"
385 " SELECT count(*), "
386 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
387 " FROM dbx"
388 " GROUP BY 2 ORDER BY 2;",
389 db_name("repository")
390 );
391 nPageFree = db_int(0, "PRAGMA freelist_count");
392 db_multi_exec(
393 "INSERT INTO piechart(amt,label) VALUES(%d,'(freelist)')",
394 nPageFree
395 );
396 nPageTotal = db_int(0, "SELECT sum(amt) FROM piechart");
397 nPageSmall = db_int(0, "SELECT sum(amt) FROM piechart WHERE amt<%d",
398 nPageTotal/50);
399 db_multi_exec(
400 "DELETE FROM piechart WHERE amt<%d;"
401 "INSERT INTO piechart(amt,label) VALUES(%d,'(other)')",
402 nPageTotal/50, nPageSmall
403 );
404 @ <center><svg width='800' height='600'>
405 piechart_render(800,600);
406 @ </svg>
407 style_footer();
408 }
409

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button