Fossil SCM
Further improvements to the /cachestat page.
Commit
3af3ffdf443e77e35b639f4d4dadbf26a7b0b8fef2409e98c0adc83afd34dbf2
Parent
cfb716fb83c0e1c…
1 file changed
+36
-33
+36
-33
| --- src/cache.c | ||
| +++ src/cache.c | ||
| @@ -402,82 +402,85 @@ | ||
| 402 | 402 | */ |
| 403 | 403 | void cache_page(void){ |
| 404 | 404 | sqlite3 *db = 0; |
| 405 | 405 | sqlite3_stmt *pStmt; |
| 406 | 406 | int doInit; |
| 407 | + char *zDbName = cacheName(); | |
| 408 | + int nEntry = 0; | |
| 409 | + int mxEntry = 0; | |
| 407 | 410 | char zBuf[100]; |
| 408 | 411 | |
| 409 | 412 | login_check_credentials(); |
| 410 | 413 | if( !g.perm.Setup ){ login_needed(0); return; } |
| 411 | 414 | style_set_current_feature("cache"); |
| 412 | 415 | style_header("Web Cache Status"); |
| 416 | + style_submenu_element("Refresh","%R/cachestat"); | |
| 413 | 417 | doInit = P("init")!=0 && cgi_csrf_safe(2); |
| 414 | 418 | db = cacheOpen(doInit); |
| 415 | - if( db==0 ){ | |
| 416 | - @ <form method="post"> | |
| 417 | - login_insert_csrf_secret(); | |
| 418 | - @ The web-page cache is disabled for this repository | |
| 419 | - @ <input type="submit" name="init" value="Enable"> | |
| 420 | - @ </form> | |
| 421 | - }else{ | |
| 422 | - char *zDbName = cacheName(); | |
| 423 | - int nEntry = 0; | |
| 424 | - int mxEntry = 0; | |
| 425 | - if( P("clearcache")!=0 && cgi_csrf_safe(2) ){ | |
| 419 | + if( db!=0 ){ | |
| 420 | + if( P("clear")!=0 && cgi_csrf_safe(2) ){ | |
| 426 | 421 | sqlite3_exec(db, "DELETE FROM cache; DELETE FROM blob; VACUUM;",0,0,0); |
| 427 | 422 | } |
| 428 | 423 | cache_register_sizename(db); |
| 429 | 424 | pStmt = cacheStmt(db, |
| 430 | 425 | "SELECT key, sz, nRef, datetime(tm,'unixepoch')" |
| 431 | 426 | " FROM cache" |
| 432 | 427 | " ORDER BY (tm + 3600*min(nRef,48)) DESC" |
| 433 | 428 | ); |
| 434 | 429 | if( pStmt ){ |
| 435 | - @ <ol> | |
| 436 | 430 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 437 | 431 | const unsigned char *zName = sqlite3_column_text(pStmt,0); |
| 438 | 432 | char *zHash = cache_hash_of_key((const char*)zName); |
| 433 | + if( nEntry==0 ){ | |
| 434 | + @ <h2>Current Cache Entries:</h2> | |
| 435 | + @ <ol> | |
| 436 | + } | |
| 439 | 437 | @ <li><p>%z(href("%R/cacheget?key=%T",zName))%h(zName)</a><br> |
| 440 | - @ size: %,lld(sqlite3_column_int64(pStmt,1)) | |
| 441 | - @ hit-count: %d(sqlite3_column_int(pStmt,2)) | |
| 442 | - @ last-access: %s(sqlite3_column_text(pStmt,3)) \ | |
| 438 | + @ size: %,lld(sqlite3_column_int64(pStmt,1)), | |
| 439 | + @ hit-count: %d(sqlite3_column_int(pStmt,2)), | |
| 440 | + @ last-access: %s(sqlite3_column_text(pStmt,3))Z \ | |
| 443 | 441 | if( zHash ){ |
| 444 | - @ %z(href("%R/timeline?c=%S",zHash))check-in</a>\ | |
| 442 | + @ → %z(href("%R/timeline?c=%S",zHash))checkin info</a>\ | |
| 445 | 443 | fossil_free(zHash); |
| 446 | 444 | } |
| 447 | 445 | @ </p></li> |
| 448 | 446 | nEntry++; |
| 449 | 447 | } |
| 450 | 448 | sqlite3_finalize(pStmt); |
| 451 | - @ </ol> | |
| 449 | + if( nEntry ){ | |
| 450 | + @ </ol> | |
| 451 | + } | |
| 452 | 452 | } |
| 453 | - zDbName = cacheName(); | |
| 453 | + } | |
| 454 | + @ <h2>About The Web-Cache</h2> | |
| 455 | + @ <p> | |
| 456 | + @ The web-cache is a separate database file that holds cached copies | |
| 457 | + @ tarballs, ZIP archives, and other pages that are expensive to compute | |
| 458 | + @ and are likely to be reused. | |
| 459 | + @ <form method="post"> | |
| 460 | + login_insert_csrf_secret(); | |
| 461 | + @ <ul> | |
| 462 | + if( db==0 ){ | |
| 463 | + @ <li> Web-cache is currently disabled. | |
| 464 | + @ <input type="submit" name="init" value="Enable"> | |
| 465 | + }else{ | |
| 454 | 466 | bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName, ExtFILE)); |
| 455 | 467 | mxEntry = db_get_int("max-cache-entry",10); |
| 456 | - @ <p> | |
| 457 | - @ </p> | |
| 458 | - @ <h2>About The Web-Cache</h2> | |
| 459 | - @ <p> | |
| 460 | - @ The web-cache is a separate database file that holds cached copies | |
| 461 | - @ tarballs, ZIP archives, and other pages that are expensive to compute | |
| 462 | - @ and are likely to be reused. | |
| 463 | - @ <form method="post"> | |
| 464 | - @ <ul> | |
| 465 | 468 | @ <li> Filename of the cache database: <b>%h(zDbName)</b> |
| 466 | 469 | @ <li> Size of the cache database: %s(zBuf) |
| 467 | - @ <li> Maximum number of entries: %d(mxEntry); | |
| 468 | - @ <li> Number of slots used: %d(nEntry) | |
| 470 | + @ <li> Maximum number of entries: %d(mxEntry) | |
| 471 | + @ <li> Number of cache entries used: %d(nEntry) | |
| 469 | 472 | @ <li> Change the max-cache-entry setting on the |
| 470 | 473 | @ <a href="%R/setup_settings">Settings</a> page to adjust the |
| 471 | 474 | @ maximum number of entries in the cache. |
| 472 | 475 | @ <li><input type="submit" name="clear" value="Clear the cache"> |
| 473 | 476 | @ <li> Disable the cache by manually deleting the cache database file. |
| 474 | - @ </ul> | |
| 475 | - @ </form> | |
| 476 | - fossil_free(zDbName); | |
| 477 | - sqlite3_close(db); | |
| 478 | 477 | } |
| 478 | + @ </ul> | |
| 479 | + @ </form> | |
| 480 | + fossil_free(zDbName); | |
| 481 | + if( db ) sqlite3_close(db); | |
| 479 | 482 | style_finish_page(); |
| 480 | 483 | } |
| 481 | 484 | |
| 482 | 485 | /* |
| 483 | 486 | ** WEBPAGE: cacheget |
| 484 | 487 |
| --- src/cache.c | |
| +++ src/cache.c | |
| @@ -402,82 +402,85 @@ | |
| 402 | */ |
| 403 | void cache_page(void){ |
| 404 | sqlite3 *db = 0; |
| 405 | sqlite3_stmt *pStmt; |
| 406 | int doInit; |
| 407 | char zBuf[100]; |
| 408 | |
| 409 | login_check_credentials(); |
| 410 | if( !g.perm.Setup ){ login_needed(0); return; } |
| 411 | style_set_current_feature("cache"); |
| 412 | style_header("Web Cache Status"); |
| 413 | doInit = P("init")!=0 && cgi_csrf_safe(2); |
| 414 | db = cacheOpen(doInit); |
| 415 | if( db==0 ){ |
| 416 | @ <form method="post"> |
| 417 | login_insert_csrf_secret(); |
| 418 | @ The web-page cache is disabled for this repository |
| 419 | @ <input type="submit" name="init" value="Enable"> |
| 420 | @ </form> |
| 421 | }else{ |
| 422 | char *zDbName = cacheName(); |
| 423 | int nEntry = 0; |
| 424 | int mxEntry = 0; |
| 425 | if( P("clearcache")!=0 && cgi_csrf_safe(2) ){ |
| 426 | sqlite3_exec(db, "DELETE FROM cache; DELETE FROM blob; VACUUM;",0,0,0); |
| 427 | } |
| 428 | cache_register_sizename(db); |
| 429 | pStmt = cacheStmt(db, |
| 430 | "SELECT key, sz, nRef, datetime(tm,'unixepoch')" |
| 431 | " FROM cache" |
| 432 | " ORDER BY (tm + 3600*min(nRef,48)) DESC" |
| 433 | ); |
| 434 | if( pStmt ){ |
| 435 | @ <ol> |
| 436 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 437 | const unsigned char *zName = sqlite3_column_text(pStmt,0); |
| 438 | char *zHash = cache_hash_of_key((const char*)zName); |
| 439 | @ <li><p>%z(href("%R/cacheget?key=%T",zName))%h(zName)</a><br> |
| 440 | @ size: %,lld(sqlite3_column_int64(pStmt,1)) |
| 441 | @ hit-count: %d(sqlite3_column_int(pStmt,2)) |
| 442 | @ last-access: %s(sqlite3_column_text(pStmt,3)) \ |
| 443 | if( zHash ){ |
| 444 | @ %z(href("%R/timeline?c=%S",zHash))check-in</a>\ |
| 445 | fossil_free(zHash); |
| 446 | } |
| 447 | @ </p></li> |
| 448 | nEntry++; |
| 449 | } |
| 450 | sqlite3_finalize(pStmt); |
| 451 | @ </ol> |
| 452 | } |
| 453 | zDbName = cacheName(); |
| 454 | bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName, ExtFILE)); |
| 455 | mxEntry = db_get_int("max-cache-entry",10); |
| 456 | @ <p> |
| 457 | @ </p> |
| 458 | @ <h2>About The Web-Cache</h2> |
| 459 | @ <p> |
| 460 | @ The web-cache is a separate database file that holds cached copies |
| 461 | @ tarballs, ZIP archives, and other pages that are expensive to compute |
| 462 | @ and are likely to be reused. |
| 463 | @ <form method="post"> |
| 464 | @ <ul> |
| 465 | @ <li> Filename of the cache database: <b>%h(zDbName)</b> |
| 466 | @ <li> Size of the cache database: %s(zBuf) |
| 467 | @ <li> Maximum number of entries: %d(mxEntry); |
| 468 | @ <li> Number of slots used: %d(nEntry) |
| 469 | @ <li> Change the max-cache-entry setting on the |
| 470 | @ <a href="%R/setup_settings">Settings</a> page to adjust the |
| 471 | @ maximum number of entries in the cache. |
| 472 | @ <li><input type="submit" name="clear" value="Clear the cache"> |
| 473 | @ <li> Disable the cache by manually deleting the cache database file. |
| 474 | @ </ul> |
| 475 | @ </form> |
| 476 | fossil_free(zDbName); |
| 477 | sqlite3_close(db); |
| 478 | } |
| 479 | style_finish_page(); |
| 480 | } |
| 481 | |
| 482 | /* |
| 483 | ** WEBPAGE: cacheget |
| 484 |
| --- src/cache.c | |
| +++ src/cache.c | |
| @@ -402,82 +402,85 @@ | |
| 402 | */ |
| 403 | void cache_page(void){ |
| 404 | sqlite3 *db = 0; |
| 405 | sqlite3_stmt *pStmt; |
| 406 | int doInit; |
| 407 | char *zDbName = cacheName(); |
| 408 | int nEntry = 0; |
| 409 | int mxEntry = 0; |
| 410 | char zBuf[100]; |
| 411 | |
| 412 | login_check_credentials(); |
| 413 | if( !g.perm.Setup ){ login_needed(0); return; } |
| 414 | style_set_current_feature("cache"); |
| 415 | style_header("Web Cache Status"); |
| 416 | style_submenu_element("Refresh","%R/cachestat"); |
| 417 | doInit = P("init")!=0 && cgi_csrf_safe(2); |
| 418 | db = cacheOpen(doInit); |
| 419 | if( db!=0 ){ |
| 420 | if( P("clear")!=0 && cgi_csrf_safe(2) ){ |
| 421 | sqlite3_exec(db, "DELETE FROM cache; DELETE FROM blob; VACUUM;",0,0,0); |
| 422 | } |
| 423 | cache_register_sizename(db); |
| 424 | pStmt = cacheStmt(db, |
| 425 | "SELECT key, sz, nRef, datetime(tm,'unixepoch')" |
| 426 | " FROM cache" |
| 427 | " ORDER BY (tm + 3600*min(nRef,48)) DESC" |
| 428 | ); |
| 429 | if( pStmt ){ |
| 430 | while( sqlite3_step(pStmt)==SQLITE_ROW ){ |
| 431 | const unsigned char *zName = sqlite3_column_text(pStmt,0); |
| 432 | char *zHash = cache_hash_of_key((const char*)zName); |
| 433 | if( nEntry==0 ){ |
| 434 | @ <h2>Current Cache Entries:</h2> |
| 435 | @ <ol> |
| 436 | } |
| 437 | @ <li><p>%z(href("%R/cacheget?key=%T",zName))%h(zName)</a><br> |
| 438 | @ size: %,lld(sqlite3_column_int64(pStmt,1)), |
| 439 | @ hit-count: %d(sqlite3_column_int(pStmt,2)), |
| 440 | @ last-access: %s(sqlite3_column_text(pStmt,3))Z \ |
| 441 | if( zHash ){ |
| 442 | @ → %z(href("%R/timeline?c=%S",zHash))checkin info</a>\ |
| 443 | fossil_free(zHash); |
| 444 | } |
| 445 | @ </p></li> |
| 446 | nEntry++; |
| 447 | } |
| 448 | sqlite3_finalize(pStmt); |
| 449 | if( nEntry ){ |
| 450 | @ </ol> |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | @ <h2>About The Web-Cache</h2> |
| 455 | @ <p> |
| 456 | @ The web-cache is a separate database file that holds cached copies |
| 457 | @ tarballs, ZIP archives, and other pages that are expensive to compute |
| 458 | @ and are likely to be reused. |
| 459 | @ <form method="post"> |
| 460 | login_insert_csrf_secret(); |
| 461 | @ <ul> |
| 462 | if( db==0 ){ |
| 463 | @ <li> Web-cache is currently disabled. |
| 464 | @ <input type="submit" name="init" value="Enable"> |
| 465 | }else{ |
| 466 | bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName, ExtFILE)); |
| 467 | mxEntry = db_get_int("max-cache-entry",10); |
| 468 | @ <li> Filename of the cache database: <b>%h(zDbName)</b> |
| 469 | @ <li> Size of the cache database: %s(zBuf) |
| 470 | @ <li> Maximum number of entries: %d(mxEntry) |
| 471 | @ <li> Number of cache entries used: %d(nEntry) |
| 472 | @ <li> Change the max-cache-entry setting on the |
| 473 | @ <a href="%R/setup_settings">Settings</a> page to adjust the |
| 474 | @ maximum number of entries in the cache. |
| 475 | @ <li><input type="submit" name="clear" value="Clear the cache"> |
| 476 | @ <li> Disable the cache by manually deleting the cache database file. |
| 477 | } |
| 478 | @ </ul> |
| 479 | @ </form> |
| 480 | fossil_free(zDbName); |
| 481 | if( db ) sqlite3_close(db); |
| 482 | style_finish_page(); |
| 483 | } |
| 484 | |
| 485 | /* |
| 486 | ** WEBPAGE: cacheget |
| 487 |