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.
This commit is contained in:
Chad Birch
2015-11-18 14:21:00 -07:00
parent fa0a50806b
commit 5fb32a69a5

View File

@@ -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)