Fossil SCM
Add a web-page for viewing the status of the web cache. Accessible as a submenu off of the stat page.
Commit
05477b2e06740cce6e5f6476accb8a509d01719a
Parent
34ea8daf905f6b7…
2 files changed
+46
+2
-1
+46
| --- src/cache.c | ||
| +++ src/cache.c | ||
| @@ -316,5 +316,51 @@ | ||
| 316 | 316 | }else{ |
| 317 | 317 | fossil_fatal("Unknown subcommand \"%s\"." |
| 318 | 318 | " Should be one of: clear init list status", zCmd); |
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | + | |
| 322 | +/* | |
| 323 | +** WEBPAGE: cachestat | |
| 324 | +** | |
| 325 | +** Show information about the webpage cache | |
| 326 | +*/ | |
| 327 | +void cache_page(void){ | |
| 328 | + sqlite3 *db; | |
| 329 | + sqlite3_stmt *pStmt; | |
| 330 | + char *zDbName; | |
| 331 | + char zBuf[100]; | |
| 332 | + | |
| 333 | + login_check_credentials(); | |
| 334 | + if( !g.perm.Setup ){ login_needed(); return; } | |
| 335 | + style_header("Web Cache Status"); | |
| 336 | + db = cacheOpen(0); | |
| 337 | + if( db==0 ){ | |
| 338 | + @ The web-page cache is disabled for this repository | |
| 339 | + }else{ | |
| 340 | + char *zDbName = cacheName(); | |
| 341 | + cache_register_sizename(db); | |
| 342 | + pStmt = cacheStmt(db, | |
| 343 | + "SELECT key, sizename(sz), nRef, datetime(tm,'unixepoch')" | |
| 344 | + " FROM cache" | |
| 345 | + " ORDER BY tm DESC" | |
| 346 | + ); | |
| 347 | + if( pStmt ){ | |
| 348 | + @ <ol> | |
| 349 | + while( sqlite3_step(pStmt)==SQLITE_ROW ){ | |
| 350 | + @ <li><p>%h(sqlite3_column_text(pStmt,0))<br> | |
| 351 | + @ size: %s(sqlite3_column_text(pStmt,1)) | |
| 352 | + @ hit-count: %d(sqlite3_column_int(pStmt,2)) | |
| 353 | + @ last-access: %s(sqlite3_column_text(pStmt,3))</p></li> | |
| 354 | + } | |
| 355 | + sqlite3_finalize(pStmt); | |
| 356 | + @ </ol> | |
| 357 | + } | |
| 358 | + zDbName = cacheName(); | |
| 359 | + bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName)); | |
| 360 | + @ <p>cache-file name: %h(zDbName)</p> | |
| 361 | + @ <p>cache-file size: %s(zBuf)</p> | |
| 362 | + fossil_free(zDbName); | |
| 363 | + sqlite3_close(db); | |
| 364 | + } | |
| 365 | + style_footer(); | |
| 366 | +} | |
| 321 | 367 |
| --- src/cache.c | |
| +++ src/cache.c | |
| @@ -316,5 +316,51 @@ | |
| 316 | }else{ |
| 317 | fossil_fatal("Unknown subcommand \"%s\"." |
| 318 | " Should be one of: clear init list status", zCmd); |
| 319 | } |
| 320 | } |
| 321 |
| --- src/cache.c | |
| +++ src/cache.c | |
| @@ -316,5 +316,51 @@ | |
| 316 | }else{ |
| 317 | fossil_fatal("Unknown subcommand \"%s\"." |
| 318 | " Should be one of: clear init list status", zCmd); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | ** WEBPAGE: cachestat |
| 324 | ** |
| 325 | ** Show information about the webpage cache |
| 326 | */ |
| 327 | void cache_page(void){ |
| 328 | sqlite3 *db; |
| 329 | sqlite3_stmt *pStmt; |
| 330 | char *zDbName; |
| 331 | char zBuf[100]; |
| 332 | |
| 333 | login_check_credentials(); |
| 334 | if( !g.perm.Setup ){ login_needed(); return; } |
| 335 | style_header("Web Cache Status"); |
| 336 | db = cacheOpen(0); |
| 337 | if( db==0 ){ |
| 338 | @ The web-page cache is disabled for this repository |
| 339 | }else{ |
| 340 | char *zDbName = cacheName(); |
| 341 | cache_register_sizename(db); |
| 342 | pStmt = cacheStmt(db, |
| 343 | "SELECT key, sizename(sz), nRef, datetime(tm,'unixepoch')" |
| 344 | " FROM cache" |
| 345 | " ORDER BY tm DESC" |
| 346 | ); |
| 347 | if( pStmt ){ |
| 348 | @ <ol> |
| 349 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 350 | @ <li><p>%h(sqlite3_column_text(pStmt,0))<br> |
| 351 | @ size: %s(sqlite3_column_text(pStmt,1)) |
| 352 | @ hit-count: %d(sqlite3_column_int(pStmt,2)) |
| 353 | @ last-access: %s(sqlite3_column_text(pStmt,3))</p></li> |
| 354 | } |
| 355 | sqlite3_finalize(pStmt); |
| 356 | @ </ol> |
| 357 | } |
| 358 | zDbName = cacheName(); |
| 359 | bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName)); |
| 360 | @ <p>cache-file name: %h(zDbName)</p> |
| 361 | @ <p>cache-file size: %s(zBuf)</p> |
| 362 | fossil_free(zDbName); |
| 363 | sqlite3_close(db); |
| 364 | } |
| 365 | style_footer(); |
| 366 | } |
| 367 |
+2
-1
| --- src/stat.c | ||
| +++ src/stat.c | ||
| @@ -25,11 +25,11 @@ | ||
| 25 | 25 | |
| 26 | 26 | /* |
| 27 | 27 | ** For a sufficiently large integer, provide an alternative |
| 28 | 28 | ** representation as MB or GB or TB. |
| 29 | 29 | */ |
| 30 | -static void bigSizeName(int nOut, char *zOut, sqlite3_int64 v){ | |
| 30 | +void bigSizeName(int nOut, char *zOut, sqlite3_int64 v){ | |
| 31 | 31 | if( v<100000 ){ |
| 32 | 32 | sqlite3_snprintf(nOut, zOut, "%lld bytes", v); |
| 33 | 33 | }else if( v<1000000000 ){ |
| 34 | 34 | sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fMB)", |
| 35 | 35 | v, (double)v/1000000.0); |
| @@ -57,10 +57,11 @@ | ||
| 57 | 57 | brief = P("brief")!=0; |
| 58 | 58 | style_header("Repository Statistics"); |
| 59 | 59 | if( g.perm.Admin ){ |
| 60 | 60 | style_submenu_element("URLs", "URLs and Checkouts", "urllist"); |
| 61 | 61 | style_submenu_element("Schema", "Repository Schema", "repo_schema"); |
| 62 | + style_submenu_element("Web-Cache", "Web-Cache Stats", "cachestat"); | |
| 62 | 63 | } |
| 63 | 64 | @ <table class="label-value"> |
| 64 | 65 | @ <tr><th>Repository Size:</th><td> |
| 65 | 66 | fsize = file_size(g.zRepositoryName); |
| 66 | 67 | bigSizeName(sizeof(zBuf), zBuf, fsize); |
| 67 | 68 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -25,11 +25,11 @@ | |
| 25 | |
| 26 | /* |
| 27 | ** For a sufficiently large integer, provide an alternative |
| 28 | ** representation as MB or GB or TB. |
| 29 | */ |
| 30 | static void bigSizeName(int nOut, char *zOut, sqlite3_int64 v){ |
| 31 | if( v<100000 ){ |
| 32 | sqlite3_snprintf(nOut, zOut, "%lld bytes", v); |
| 33 | }else if( v<1000000000 ){ |
| 34 | sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fMB)", |
| 35 | v, (double)v/1000000.0); |
| @@ -57,10 +57,11 @@ | |
| 57 | brief = P("brief")!=0; |
| 58 | style_header("Repository Statistics"); |
| 59 | if( g.perm.Admin ){ |
| 60 | style_submenu_element("URLs", "URLs and Checkouts", "urllist"); |
| 61 | style_submenu_element("Schema", "Repository Schema", "repo_schema"); |
| 62 | } |
| 63 | @ <table class="label-value"> |
| 64 | @ <tr><th>Repository Size:</th><td> |
| 65 | fsize = file_size(g.zRepositoryName); |
| 66 | bigSizeName(sizeof(zBuf), zBuf, fsize); |
| 67 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -25,11 +25,11 @@ | |
| 25 | |
| 26 | /* |
| 27 | ** For a sufficiently large integer, provide an alternative |
| 28 | ** representation as MB or GB or TB. |
| 29 | */ |
| 30 | void bigSizeName(int nOut, char *zOut, sqlite3_int64 v){ |
| 31 | if( v<100000 ){ |
| 32 | sqlite3_snprintf(nOut, zOut, "%lld bytes", v); |
| 33 | }else if( v<1000000000 ){ |
| 34 | sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fMB)", |
| 35 | v, (double)v/1000000.0); |
| @@ -57,10 +57,11 @@ | |
| 57 | brief = P("brief")!=0; |
| 58 | style_header("Repository Statistics"); |
| 59 | if( g.perm.Admin ){ |
| 60 | style_submenu_element("URLs", "URLs and Checkouts", "urllist"); |
| 61 | style_submenu_element("Schema", "Repository Schema", "repo_schema"); |
| 62 | style_submenu_element("Web-Cache", "Web-Cache Stats", "cachestat"); |
| 63 | } |
| 64 | @ <table class="label-value"> |
| 65 | @ <tr><th>Repository Size:</th><td> |
| 66 | fsize = file_size(g.zRepositoryName); |
| 67 | bigSizeName(sizeof(zBuf), zBuf, fsize); |
| 68 |