mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 22:15:14 +00:00
Update the query stats in the footer to track cache hits/misses (WIP)
Update the query stats in the footer to track cache hits and misses per request
This commit is contained in:
parent
f445565253
commit
64cc786394
5 changed files with 44 additions and 1 deletions
|
|
@ -38,4 +38,14 @@ footer {
|
|||
footer:hover {
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
|
||||
.cache-stats {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.cache-stats span {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
before_action :set_paper_trail_whodunnit
|
||||
before_action :initialize_cache_counters
|
||||
|
||||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
||||
allow_browser versions: :modern
|
||||
|
|
@ -21,4 +22,17 @@ class ApplicationController < ActionController::Base
|
|||
redirect_to root_path, alert: "Please sign in first!"
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_cache_counters
|
||||
Thread.current[:cache_hits] = 0
|
||||
Thread.current[:cache_misses] = 0
|
||||
end
|
||||
|
||||
def increment_cache_hits
|
||||
Thread.current[:cache_hits] += 1
|
||||
end
|
||||
|
||||
def increment_cache_misses
|
||||
Thread.current[:cache_misses] += 1
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,2 +1,7 @@
|
|||
module ApplicationHelper
|
||||
def cache_stats
|
||||
hits = Thread.current[:cache_hits] || 0
|
||||
misses = Thread.current[:cache_misses] || 0
|
||||
{ hits: hits, misses: misses }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
Build <%= Rails.application.config.git_version %> from <%= time_ago_in_words(Rails.application.config.server_start_time) %> ago.
|
||||
<%= pluralize(Heartbeat.cached_recent_count, 'heartbeat') %> in the last 24 hours.
|
||||
(DB: <%= pluralize(QueryCount::Counter.counter, "query") %>, <%= QueryCount::Counter.counter_cache %> cached)
|
||||
(CACHE: <%= cache_stats[:hits] %> hits, <%= cache_stats[:misses] %> misses)
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
|
|
|||
|
|
@ -23,5 +23,18 @@ module Harbor
|
|||
#
|
||||
# config.time_zone = "Central Time (US & Canada)"
|
||||
# config.eager_load_paths << Rails.root.join("extras")
|
||||
|
||||
ActiveSupport::Notifications.subscribe('cache_read.active_support') do |*args|
|
||||
event = ActiveSupport::Notifications::Event.new(*args)
|
||||
if event.payload[:hit]
|
||||
Thread.current[:cache_hits] += 1
|
||||
else
|
||||
Thread.current[:cache_misses] += 1
|
||||
end
|
||||
end
|
||||
|
||||
ActiveSupport::Notifications.subscribe('cache_fetch_hit.active_support') do |*args|
|
||||
Thread.current[:cache_hits] += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue