Merge pull request #352 from CartoDB/206-clean-up-non-zero-padded-reads
206 clean up non zero padded reads
This commit is contained in:
commit
01b96fe276
@ -118,12 +118,9 @@ class UserMetricsService:
|
||||
for date in self.__generate_date_range(date_from, date_to):
|
||||
redis_prefix = self.__parse_redis_prefix(key_prefix, entity_name,
|
||||
service, metric, date)
|
||||
score = self._redis_connection.zscore(redis_prefix, date.day)
|
||||
aggregated_metric += int(score) if score else 0
|
||||
zero_padded_day = date.strftime(self.DAY_OF_MONTH_ZERO_PADDED)
|
||||
if str(date.day) != zero_padded_day:
|
||||
score = self._redis_connection.zscore(redis_prefix, zero_padded_day)
|
||||
aggregated_metric += int(score) if score else 0
|
||||
score = self._redis_connection.zscore(redis_prefix, zero_padded_day)
|
||||
aggregated_metric += int(score) if score else 0
|
||||
|
||||
return aggregated_metric
|
||||
|
||||
|
@ -90,19 +90,6 @@ class TestUserService(TestCase):
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '01', 400)
|
||||
assert us.used_quota(self.NOKIA_GEOCODER, date(2015, 6,1)) == 400
|
||||
|
||||
@freeze_time("2015-06-01")
|
||||
def test_should_account_for_wrongly_stored_non_padded_keys(self):
|
||||
us = self.__build_user_service('test_user')
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '1', 400)
|
||||
assert us.used_quota(self.NOKIA_GEOCODER, date(2015, 6,1)) == 400
|
||||
|
||||
@freeze_time("2015-06-01")
|
||||
def test_should_sum_amounts_from_both_key_formats(self):
|
||||
us = self.__build_user_service('test_user')
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '1', 400)
|
||||
self.redis_conn.zincrby('user:test_user:geocoder_here:success_responses:201506', '01', 300)
|
||||
assert us.used_quota(self.NOKIA_GEOCODER, date(2015, 6,1)) == 700
|
||||
|
||||
@freeze_time("2015-06-15")
|
||||
def test_should_not_request_redis_twice_when_unneeded(self):
|
||||
class MockRedisWithCounter(MockRedis):
|
||||
|
Loading…
Reference in New Issue
Block a user