mozilla/affiliates — pull request #184 by Osmose (2014-04-08 02:54:30+00:00)
Title: Bug 976782: Milestones

Milestones are small blurbs describing recent activity. The dashboard displays 4 of them. They are generated dynamically and are:

- A milestone about the number of link clicks you've received.
- A milestone about the number of Firefox Downloads you've generated.
- A milestone about the number of image banners you've created.
- A milestone about the number of text banners you've created.

I didn't want to worry about having to detect when a user actually hits a milestone and storing it in the database, especially because the question of "when should we store a milestone that just tells them how close they are to a goal?" is an annoying one to answer well.

Instead, I decided to just have them generated on-demand. That way, we only generate milestones for users that are logging in and seeing them, and can cache the results for 24 hours (which isn't currently implemented yet, but will be later).

Still, the logic for generating these milestones is messy. [Bug 976780](https://bugzilla.mozilla.org/show_bug.cgi?id=976780) links to a [Google Doc](https://docs.google.com/spreadsheet/ccc?key=0AmuT5rQkLH20dGVjWnhxaldtcndGRVNDLTFBQ1FuZnc&usp=drive_web#gid=0) that defines the milestones we want to allow to be displayed.

The only other thing I'd mention is to make sure you understand how we store clicks: Links have a set of many Datapoints that associate a click/download count with a certain date. Datapoints only persist for up to 90 days; after that point, their metrics are added to aggregate totals stored on the Link objects. This is why we have two separate totals, and why the aggregate click count is separate from the total click count and signifies clicks that we don't know the date of.