Skip to content

Commit

Permalink
Merge pull request #272 from magopian/1059964-add-new-old-lwt-update-…
Browse files Browse the repository at this point in the history
…counts

add new and old update counts for LWT (bug 1059964)
  • Loading branch information
magopian committed Sep 10, 2014
2 parents 6619854 + 4e20a95 commit e58be85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion apps/stats/fixtures/files/src/theme_update_counts.hive
@@ -1,2 +1,4 @@
2014-07-10 813 gp 7
2014-07-10 813 gp 8
2014-07-10 813 foo 6
2014-07-10 15663 foo 7
2014-07-10 3615 \N 2
12 changes: 10 additions & 2 deletions apps/stats/management/commands/theme_update_counts_from_file.py
Expand Up @@ -101,8 +101,16 @@ def handle(self, *args, **options):
if addon_id not in addons:
continue

theme_update_counts[addon_id] = ThemeUpdateCount(
addon_id=addon_id, date=day, count=count)
# Memoize the ThemeUpdateCount.
if addon_id in theme_update_counts:
tuc = theme_update_counts[addon_id]
else:
tuc = ThemeUpdateCount(addon_id=addon_id, date=day,
count=0)
theme_update_counts[addon_id] = tuc

# We can now fill the ThemeUpdateCount object.
tuc.count += count

# Create in bulk: this is much faster.
ThemeUpdateCount.objects.bulk_create(theme_update_counts.values(), 100)
Expand Down
6 changes: 4 additions & 2 deletions apps/stats/tests/test_commands.py
Expand Up @@ -70,8 +70,10 @@ def test_theme_update_counts_from_file(self):
date='2014-07-10')
eq_(ThemeUpdateCount.objects.all().count(), 2)
eq_(ThemeUpdateCount.objects.get(addon_id=3615).count, 2)
# Persona 813 has addon id 15663
eq_(ThemeUpdateCount.objects.get(addon_id=15663).count, 7)
# Persona 813 has addon id 15663: we need the count to be the sum of
# the "old" request on the persona_id 813 (only the one with the source
# "gp") and the "new" request on the addon_id 15663.
eq_(ThemeUpdateCount.objects.get(addon_id=15663).count, 15)

def test_update_theme_popularity_movers(self):
# Create ThemeUpdateCount entries for the persona 559 with addon_id
Expand Down

0 comments on commit e58be85

Please sign in to comment.