discourse/discourse — pull request #2999 by riking (2014-11-24 16:05:40+00:00)
Title: FIX: Topic referrals by user were wrong

This commit fixes the "Top Referrers (Last 30 Days)" display in the
Admin panel, specifically the "Topics" column. Previously, the Clicks
and Topics column of the table would be identical. This commit fixes
that by counting the number of different topics that were referred to.

Raw SQL queries are used because it was easier for me to write, and it
was easier to extract the data needed to pass on from the first query to
the second (the user ids).

The data shuffling after the queries shouldn't be too bad, I just needed
to get it into the report format. Not sure how I would eliminate the
.sort_by at the end without having to preserve order everywhere, which
is not a guarantee I am willing to rely on. (The second query is
unordered for this reason.)

---

Fixes discrepancy noticed here and since degraded https://meta.discourse.org/t/top-referrers-difference-between-views-and-topics/15812/6

## Before | After

![image](https://cloud.githubusercontent.com/assets/627891/5168028/acf487fe-73b0-11e4-9cba-4182e0cd9ce0.png)