Commit 7aeba41b07d7cda47548e0700bfc379925837c6b
1 parent
8369073c
Exists in
master
and in
1 other branch
bugfix: update cache hit/miss counters to use utc
also update test to ensure we're using UTC for dates and times
Showing
3 changed files
with
8 additions
and
7 deletions
Show diff stats
app/models/choice.rb
... | ... | @@ -117,7 +117,7 @@ class Choice < ActiveRecord::Base |
117 | 117 | return if previous_choices.empty? |
118 | 118 | inserts = [] |
119 | 119 | |
120 | - timestring = Time.now.to_s(:db) #isn't rails awesome? | |
120 | + timestring = Time.now.utc.to_s(:db) #isn't rails awesome? | |
121 | 121 | |
122 | 122 | #add prompts with this choice on the left |
123 | 123 | previous_choices.each do |r| | ... | ... |
app/models/question.rb
... | ... | @@ -542,11 +542,11 @@ class Question < ActiveRecord::Base |
542 | 542 | end |
543 | 543 | |
544 | 544 | def record_prompt_cache_miss |
545 | - $redis.incr(self.pq_key + "_" + Time.now.to_date.to_s + "_"+ "misses") | |
545 | + $redis.incr(self.pq_key + "_" + Time.now.utc.to_date.to_s + "_"+ "misses") | |
546 | 546 | end |
547 | 547 | |
548 | 548 | def record_prompt_cache_hit |
549 | - $redis.incr(self.pq_key + "_" + Time.now.to_date.to_s + "_"+ "hits") | |
549 | + $redis.incr(self.pq_key + "_" + Time.now.utc.to_date.to_s + "_"+ "hits") | |
550 | 550 | end |
551 | 551 | |
552 | 552 | def get_prompt_cache_misses(date) | ... | ... |
lib/tasks/test_api.rake
... | ... | @@ -362,12 +362,13 @@ namespace :test_api do |
362 | 362 | success_message = "At least 90% of prompts on catchup algorithm questions were served from cache\n" |
363 | 363 | return [success_message, false] unless question.uses_catchup? |
364 | 364 | |
365 | - misses = question.get_prompt_cache_misses(Date.yesterday).to_i | |
366 | - hits = question.get_prompt_cache_hits(Date.yesterday).to_i | |
365 | + yesterday = Time.now.utc.yesterday.to_date | |
366 | + misses = question.get_prompt_cache_misses(yesterday).to_i | |
367 | + hits = question.get_prompt_cache_hits(yesterday).to_i | |
367 | 368 | |
368 | - question.expire_prompt_cache_tracking_keys(Date.yesterday) | |
369 | + question.expire_prompt_cache_tracking_keys(yesterday) | |
369 | 370 | |
370 | - yesterday_appearances = question.appearances.count(:conditions => ['created_at >= ? AND created_at < ?', Time.now.yesterday.midnight.utc, Time.now.midnight.utc]) | |
371 | + yesterday_appearances = question.appearances.count(:conditions => ['created_at >= ? AND created_at < ?', Time.now.utc.yesterday.midnight, Time.now.utc.midnight]) | |
371 | 372 | |
372 | 373 | if misses + hits != yesterday_appearances |
373 | 374 | error_message += "Error! Question #{question.id} isn't tracking prompt cache hits and misses accurately! Expected #{yesterday_appearances}, Actual: #{misses+hits}, Hits: #{hits}, Misses: #{misses}\n" | ... | ... |