The following snippet shows the code that selects the first X users (by uid) and inserts them into the summary table.

INSERT INTO affiliates_summary
SELECT a.user_id, SUM(aa.points), 0
FROM affiliates a, affiliates_ads aa
WHERE aa.ad_id = a.ad_id
GROUP BY a.user_id
LIMIT 50;

The updated SQL should look like or similar to the following that selects the first X users (by points descending) and inserts them into the summary table.

INSERT INTO affiliates_summary
SELECT a.user_id, SUM(aa.points) as lp, 0
FROM affiliates a, affiliates_ads aa
WHERE aa.ad_id = a.ad_id AND a.user_id != 0
GROUP BY a.user_id
ORDER BY lp DESC
LIMIT 50;

I discovered this while troubleshooting an issue where a user with the most points and a high user id was not showing up as the top affiliate.

This issue seems to affect all versions of the module (4.7.x as well as 5.x).

Submitted by: drowe (a.k.a. draco2002) http://redfinsolutions.com
Sponsored by: The Public Radio Exchange http://prx.org

CommentFileSizeAuthor
affiliates_orderby.patch543 bytesdraco2002

Comments

Anonymous’s picture

Version: 4.7.x-2.0 » 5.x-1.x-dev
Assigned: Unassigned »
Status: Needs review » Reviewed & tested by the community

Thanks , that looks good to me.

I'll get that committed later today.

Anonymous’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)