From 5fb32a69a595181b60b0013de93ab2fd2b37dbbf Mon Sep 17 00:00:00 2001 From: Chad Birch Date: Wed, 18 Nov 2015 14:21:00 -0700 Subject: [PATCH] Fix VoteDetailsByDay.count_votes() This was still using the old method of calling _rowkey (which took a date argument). The date needs to be converted to a datetime, and can then be used to call _rowkey_by_datetime(). I also switched to use .get_count() instead of manually counting the columns from the row, which should probably be faster. --- r2/r2/models/vote.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/r2/r2/models/vote.py b/r2/r2/models/vote.py index 07437b30d..fbf8cab2f 100644 --- a/r2/r2/models/vote.py +++ b/r2/r2/models/vote.py @@ -493,7 +493,11 @@ class VoteDetailsByDay(tdb_cassandra.View): @classmethod def count_votes(cls, date): - return sum(1 for x in cls._cf.xget(cls._rowkey(date))) + """Return the number of votes made on a particular date.""" + # convert the date to a datetime in the correct timezone + date = datetime(date.year, date.month, date.day, tzinfo=cls.TIMEZONE) + + return cls._cf.get_count(cls._rowkey_by_datetime(date)) @tdb_cassandra.view_of(LinkVotesByAccount)