Updated add-on user counts via cron (bug 684998)

When an add-on's average daily users (ADU) exceeds the total downloads by 10,000, set the ADU equal to total downloads.
This commit is contained in:
Rob Hudson 2011-09-27 13:11:53 -07:00
Родитель fd1341da69
Коммит c158853847
3 изменённых файлов: 22 добавлений и 2 удалений

Просмотреть файл

@ -132,7 +132,12 @@ def _update_addon_average_daily_users(data, **kw):
(len(data), _update_addon_average_daily_users.rate_limit))
for pk, count in data:
Addon.objects.filter(pk=pk).update(average_daily_users=count)
addon = Addon.objects.get(pk=pk)
if (count - addon.total_downloads) > 10000:
task_log.info('Readjusted ADU counts for addon %s' % addon.slug)
addon.update(average_daily_users=addon.total_downloads)
else:
addon.update(average_daily_users=count)
@cronjobs.register

Просмотреть файл

@ -230,3 +230,18 @@ class TestHideDisabledFiles(amo.tests.TestCase):
# It should have been removed from mirror stagins.
os_mock.remove.assert_called_with(f1.mirror_file_path)
eq_(os_mock.remove.call_count, 1)
class AvgDailyUserCountTestCase(amo.tests.TestCase):
fixtures = ['base/addon_3615']
def test_adu_is_adjusted_in_cron(self):
addon = Addon.objects.get(pk=3615)
self.assertTrue(
addon.average_daily_users > addon.total_downloads + 10000,
'Unexpected ADU count. ADU of %d not greater than %d' % (
addon.average_daily_users, addon.total_downloads + 10000))
cron._update_addon_average_daily_users([(3615, 6000000)])
addon = Addon.objects.get(pk=3615)
eq_(addon.average_daily_users, addon.total_downloads)

Просмотреть файл

@ -191,7 +191,7 @@
"paypal_id": "",
"average_rating": "3.03",
"wants_contributions": false,
"average_daily_users": 497063,
"average_daily_users": 6000000,
"bayesian_rating": 3.0784799999999999,
"share_count": 8,
"get_satisfaction_company": null,