Class: QaServer::PerformanceCache
- Inherits:
-
Object
- Object
- QaServer::PerformanceCache
- Defined in:
- app/models/qa_server/performance_cache.rb
Instance Method Summary collapse
- #destroy(id) ⇒ Object
-
#initialize ⇒ PerformanceCache
constructor
A new instance of PerformanceCache.
- #log(id:) ⇒ Object
- #new_entry(authority:, action:) ⇒ Object
- #update(id:, updates: {}) ⇒ Object
- #write_all ⇒ Object
Constructor Details
#initialize ⇒ PerformanceCache
5 6 7 |
# File 'app/models/qa_server/performance_cache.rb', line 5 def initialize @cache = {} end |
Instance Method Details
#destroy(id) ⇒ Object
24 25 26 |
# File 'app/models/qa_server/performance_cache.rb', line 24 def destroy(id) @cache.delete(id) end |
#log(id:) ⇒ Object
43 44 45 46 |
# File 'app/models/qa_server/performance_cache.rb', line 43 def log(id:) Rails.logger.info("*** performance data for id: #{id} ***") Rails.logger.info(@cache[id].to_yaml) end |
#new_entry(authority:, action:) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'app/models/qa_server/performance_cache.rb', line 9 def new_entry(authority:, action:) entry = { dt_stamp: QaServer.current_time, authority: , action: action } id = SecureRandom.uuid @cache[id] = entry id end |
#update(id:, updates: {}) ⇒ Object
18 19 20 21 22 |
# File 'app/models/qa_server/performance_cache.rb', line 18 def update(id:, updates: {}) return false unless id && @cache.key?(id) entry = @cache[id] @cache[id] = entry.merge(updates) end |
#write_all ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/qa_server/performance_cache.rb', line 28 def write_all size_before = @cache.size @cache.each do |id, entry| next if incomplete? entry QaServer::PerformanceHistory.create(dt_stamp: entry[:dt_stamp], authority: entry[:authority], action: entry[:action], action_time_ms: entry[:action_time_ms], size_bytes: entry[:size_bytes], retrieve_time_ms: entry[:retrieve_time_ms], graph_load_time_ms: entry[:graph_load_time_ms], normalization_time_ms: entry[:normalization_time_ms]) @cache.delete(id) end Rails.logger.warn("0 of #{size_before} performance data records were saved") if size_before.positive? && (size_before == @cache.size) Rails.logger.info("#{size_before - @cache.size} of #{size_before} performance data records were saved") if size_before.positive? && (size_before > @cache.size) end |