From 8075fa83c3a98baa8ef17a26b41db1a743c7a3e4 Mon Sep 17 00:00:00 2001 From: bsimpson63 Date: Wed, 30 Jan 2013 15:47:56 -0500 Subject: [PATCH] Stop get_promotions_cached from combining campaigns on same link. --- r2/r2/lib/promote.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/r2/r2/lib/promote.py b/r2/r2/lib/promote.py index 680277ffc..70841bf7c 100644 --- a/r2/r2/lib/promote.py +++ b/r2/r2/lib/promote.py @@ -802,23 +802,22 @@ def get_promotion_list(user, site): def get_promotions_cached(sites): weights = get_live_promotions(sites) - if weights: - available = {} - campaigns = {} - for sr_id, sr_weights in weights.iteritems(): - if sr_id in sites: - for l, w, cid in sr_weights: - available[l] = available.get(l, 0) + w - campaigns[l] = cid - # sort the available list by weight - links = available.keys() - links.sort(key=lambda x: -available[x]) - norm = sum(available.values()) - # return a sorted list of (link, norm_weight) - return [(l, available[l] / norm, campaigns[l]) for l in links] - else: + if not weights: return [] + promos = [] + total = 0. + for sr_id, sr_weights in weights.iteritems(): + if sr_id not in sites: + continue + for link, weight, campaign in sr_weights: + total += weight + promos.append((link, weight, campaign)) + + return [(link, weight / total, campaign) + for link, weight, campaign in promos] + + def randomized_promotion_list(user, site): promos = get_promotion_list(user, site) # no promos, no problem