Fossil SCM

Further improvements to the /cachestat page.

drh 2025-04-09 13:07 trunk
Commit 3af3ffdf443e77e35b639f4d4dadbf26a7b0b8fef2409e98c0adc83afd34dbf2
1 file changed +36 -33
+36 -33
--- src/cache.c
+++ src/cache.c
@@ -402,82 +402,85 @@
402402
*/
403403
void cache_page(void){
404404
sqlite3 *db = 0;
405405
sqlite3_stmt *pStmt;
406406
int doInit;
407
+ char *zDbName = cacheName();
408
+ int nEntry = 0;
409
+ int mxEntry = 0;
407410
char zBuf[100];
408411
409412
login_check_credentials();
410413
if( !g.perm.Setup ){ login_needed(0); return; }
411414
style_set_current_feature("cache");
412415
style_header("Web Cache Status");
416
+ style_submenu_element("Refresh","%R/cachestat");
413417
doInit = P("init")!=0 && cgi_csrf_safe(2);
414418
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) ){
426421
sqlite3_exec(db, "DELETE FROM cache; DELETE FROM blob; VACUUM;",0,0,0);
427422
}
428423
cache_register_sizename(db);
429424
pStmt = cacheStmt(db,
430425
"SELECT key, sz, nRef, datetime(tm,'unixepoch')"
431426
" FROM cache"
432427
" ORDER BY (tm + 3600*min(nRef,48)) DESC"
433428
);
434429
if( pStmt ){
435
- @ <ol>
436430
while( sqlite3_step(pStmt)==SQLITE_ROW ){
437431
const unsigned char *zName = sqlite3_column_text(pStmt,0);
438432
char *zHash = cache_hash_of_key((const char*)zName);
433
+ if( nEntry==0 ){
434
+ @ <h2>Current Cache Entries:</h2>
435
+ @ <ol>
436
+ }
439437
@ <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 \
443441
if( zHash ){
444
- @ %z(href("%R/timeline?c=%S",zHash))check-in</a>\
442
+ @ &rarr; %z(href("%R/timeline?c=%S",zHash))checkin info</a>\
445443
fossil_free(zHash);
446444
}
447445
@ </p></li>
448446
nEntry++;
449447
}
450448
sqlite3_finalize(pStmt);
451
- @ </ol>
449
+ if( nEntry ){
450
+ @ </ol>
451
+ }
452452
}
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{
454466
bigSizeName(sizeof(zBuf), zBuf, file_size(zDbName, ExtFILE));
455467
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>
465468
@ <li> Filename of the cache database: <b>%h(zDbName)</b>
466469
@ <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)
469472
@ <li> Change the max-cache-entry setting on the
470473
@ <a href="%R/setup_settings">Settings</a> page to adjust the
471474
@ maximum number of entries in the cache.
472475
@ <li><input type="submit" name="clear" value="Clear the cache">
473476
@ <li> Disable the cache by manually deleting the cache database file.
474
- @ </ul>
475
- @ </form>
476
- fossil_free(zDbName);
477
- sqlite3_close(db);
478477
}
478
+ @ </ul>
479
+ @ </form>
480
+ fossil_free(zDbName);
481
+ if( db ) sqlite3_close(db);
479482
style_finish_page();
480483
}
481484
482485
/*
483486
** WEBPAGE: cacheget
484487
--- 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 @ &rarr; %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

Keyboard Shortcuts

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