Skip to content

Commit

Permalink
Less verbose stats, more stats
Browse files Browse the repository at this point in the history
  • Loading branch information
antleb committed Jan 26, 2024
1 parent 1eae4f1 commit e90c5a4
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,23 @@ public void deleteEntry(String key) {
public Map<String, Object> stats() {
DatasourceContext.setContext(CACHE_DB_NAME);

Map<String, Object> stats = new HashMap<>();
Map<String, Object> stats = new LinkedHashMap<>();

stats.put("total", jdbcTemplate.queryForObject("select count(*) from cache_entry",new Object[] {}, Integer.class));
stats.put("with_shadow", jdbcTemplate.queryForObject("select count(*) from cache_entry where shadow is not null",new Object[] {}, Integer.class));
stats.put("top10", jdbcTemplate.query("select * from cache_entry where key not in ('SHADOW_STATS_NUMBERS', 'STATS_NUMBERS') order by total_hits", (rs, rowNum) -> {
stats.put("total.top10", jdbcTemplate.query("select * from cache_entry where key not in ('SHADOW_STATS_NUMBERS', 'STATS_NUMBERS') order by total_hits limit 10", (rs, rowNum) -> {
CacheEntry entry = null;

try {
QueryWithParameters query = new ObjectMapper().readValue(rs.getString("query"), QueryWithParameters.class);
String key = rs.getString("key");
Result result = new ObjectMapper().readValue(rs.getString("result"), Result.class);

entry = new CacheEntry(key, query, result);
entry = new CacheEntry(key, query, null);

if (rs.getTimestamp("created") != null)
entry.setCreated(new Date(rs.getTimestamp("created").getTime()));
if (rs.getTimestamp("updated") != null)
entry.setUpdated(new Date(rs.getTimestamp("updated").getTime()));
if (rs.getString("shadow") != null)
entry.setShadowResult(new ObjectMapper().readValue(rs.getString("shadow"), Result.class));

entry.setTotalHits(rs.getInt("total_hits"));
entry.setSessionHits(rs.getInt("session_hits"));
Expand All @@ -223,7 +220,29 @@ public Map<String, Object> stats() {

return entry;
}));
stats.put("session.top10", jdbcTemplate.query("select * from cache_entry where key not in ('SHADOW_STATS_NUMBERS', 'STATS_NUMBERS') order by session_hits limit 10", (rs, rowNum) -> {
CacheEntry entry = null;

try {
QueryWithParameters query = new ObjectMapper().readValue(rs.getString("query"), QueryWithParameters.class);
String key = rs.getString("key");

entry = new CacheEntry(key, query, null);

if (rs.getTimestamp("created") != null)
entry.setCreated(new Date(rs.getTimestamp("created").getTime()));
if (rs.getTimestamp("updated") != null)
entry.setUpdated(new Date(rs.getTimestamp("updated").getTime()));

entry.setTotalHits(rs.getInt("total_hits"));
entry.setSessionHits(rs.getInt("session_hits"));
entry.setPinned(rs.getBoolean("pinned"));
} catch (IOException e) {
log.error("Error reading entry", e);
}

return entry;
}));
return stats;
}
}

0 comments on commit e90c5a4

Please sign in to comment.