Fossil SCM

On the /cachestat page, provide a link to the timeline check-in context for the origin of each item in the cache.

drh 2021-06-16 12:44 trunk
Commit 61c33f67b3b7d840cee8dc700924f4f6f3fc875e12049200c0b7cc72bda3602a
1 file changed +35 -1
+35 -1
--- src/cache.c
+++ src/cache.c
@@ -365,10 +365,37 @@
365365
}else{
366366
fossil_fatal("Unknown subcommand \"%s\"."
367367
" Should be one of: clear init list size status", zCmd);
368368
}
369369
}
370
+
371
+/*
372
+** Given a cache key, find the check-in hash and return it as a separate
373
+** string. The returned string is obtained from fossil_malloc() and must
374
+** be freed by the caller.
375
+**
376
+** Return NULL if not found.
377
+**
378
+** The key is usually in a format like these:
379
+**
380
+** /tarball/HASH/NAME
381
+** /zip/HASH/NAME
382
+** /sqlar/HASH/NAME
383
+*/
384
+static char *cache_hash_of_key(const char *zKey){
385
+ int i;
386
+ if( zKey==0 ) return 0;
387
+ if( zKey[0]!='/' ) return 0;
388
+ zKey++;
389
+ while( zKey[0] && zKey[0]!='/' ) zKey++;
390
+ if( zKey[0]==0 ) return 0;
391
+ zKey++;
392
+ for(i=0; zKey[i] && zKey[i]!='/'; i++){}
393
+ if( !validate16(zKey, i) ) return 0;
394
+ return fossil_strndup(zKey, i);
395
+}
396
+
370397
371398
/*
372399
** WEBPAGE: cachestat
373400
**
374401
** Show information about the webpage cache. Requires Setup privilege.
@@ -395,14 +422,21 @@
395422
);
396423
if( pStmt ){
397424
@ <ol>
398425
while( sqlite3_step(pStmt)==SQLITE_ROW ){
399426
const unsigned char *zName = sqlite3_column_text(pStmt,0);
427
+ char *zHash = cache_hash_of_key((const char*)zName);
400428
@ <li><p>%z(href("%R/cacheget?key=%T",zName))%h(zName)</a><br />
401429
@ size: %,lld(sqlite3_column_int64(pStmt,1))
402430
@ hit-count: %d(sqlite3_column_int(pStmt,2))
403
- @ last-access: %s(sqlite3_column_text(pStmt,3))</p></li>
431
+ @ last-access: %s(sqlite3_column_text(pStmt,3)) \
432
+ if( zHash ){
433
+ @ %z(href("%R/timeline?c=%S",zHash))check-in</a>\
434
+ fossil_free(zHash);
435
+ }
436
+ @ </p></li>
437
+
404438
}
405439
sqlite3_finalize(pStmt);
406440
@ </ol>
407441
}
408442
zDbName = cacheName();
409443
--- src/cache.c
+++ src/cache.c
@@ -365,10 +365,37 @@
365 }else{
366 fossil_fatal("Unknown subcommand \"%s\"."
367 " Should be one of: clear init list size status", zCmd);
368 }
369 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
371 /*
372 ** WEBPAGE: cachestat
373 **
374 ** Show information about the webpage cache. Requires Setup privilege.
@@ -395,14 +422,21 @@
395 );
396 if( pStmt ){
397 @ <ol>
398 while( sqlite3_step(pStmt)==SQLITE_ROW ){
399 const unsigned char *zName = sqlite3_column_text(pStmt,0);
 
400 @ <li><p>%z(href("%R/cacheget?key=%T",zName))%h(zName)</a><br />
401 @ size: %,lld(sqlite3_column_int64(pStmt,1))
402 @ hit-count: %d(sqlite3_column_int(pStmt,2))
403 @ last-access: %s(sqlite3_column_text(pStmt,3))</p></li>
 
 
 
 
 
 
404 }
405 sqlite3_finalize(pStmt);
406 @ </ol>
407 }
408 zDbName = cacheName();
409
--- src/cache.c
+++ src/cache.c
@@ -365,10 +365,37 @@
365 }else{
366 fossil_fatal("Unknown subcommand \"%s\"."
367 " Should be one of: clear init list size status", zCmd);
368 }
369 }
370
371 /*
372 ** Given a cache key, find the check-in hash and return it as a separate
373 ** string. The returned string is obtained from fossil_malloc() and must
374 ** be freed by the caller.
375 **
376 ** Return NULL if not found.
377 **
378 ** The key is usually in a format like these:
379 **
380 ** /tarball/HASH/NAME
381 ** /zip/HASH/NAME
382 ** /sqlar/HASH/NAME
383 */
384 static char *cache_hash_of_key(const char *zKey){
385 int i;
386 if( zKey==0 ) return 0;
387 if( zKey[0]!='/' ) return 0;
388 zKey++;
389 while( zKey[0] && zKey[0]!='/' ) zKey++;
390 if( zKey[0]==0 ) return 0;
391 zKey++;
392 for(i=0; zKey[i] && zKey[i]!='/'; i++){}
393 if( !validate16(zKey, i) ) return 0;
394 return fossil_strndup(zKey, i);
395 }
396
397
398 /*
399 ** WEBPAGE: cachestat
400 **
401 ** Show information about the webpage cache. Requires Setup privilege.
@@ -395,14 +422,21 @@
422 );
423 if( pStmt ){
424 @ <ol>
425 while( sqlite3_step(pStmt)==SQLITE_ROW ){
426 const unsigned char *zName = sqlite3_column_text(pStmt,0);
427 char *zHash = cache_hash_of_key((const char*)zName);
428 @ <li><p>%z(href("%R/cacheget?key=%T",zName))%h(zName)</a><br />
429 @ size: %,lld(sqlite3_column_int64(pStmt,1))
430 @ hit-count: %d(sqlite3_column_int(pStmt,2))
431 @ last-access: %s(sqlite3_column_text(pStmt,3)) \
432 if( zHash ){
433 @ %z(href("%R/timeline?c=%S",zHash))check-in</a>\
434 fossil_free(zHash);
435 }
436 @ </p></li>
437
438 }
439 sqlite3_finalize(pStmt);
440 @ </ol>
441 }
442 zDbName = cacheName();
443

Keyboard Shortcuts

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