Exemplo n.º 1
0
def set_live_promotions(links, weights, which=("cass", "permacache")):
    if "cass" in which:
        timer = g.stats.get_timer("promote.set_live.cass")
        timer.start()
        SponsorBoxWeightings.set_from_weights(weights)
        timer.stop()
    if "permacache" in which:
        timer = g.stats.get_timer("promote.set_live.permacache")
        timer.start()
        g.permacache.set(promotion_key(), (links, weights))
        timer.stop()
Exemplo n.º 2
0
def get_live_promotions(srids, from_permacache=True):
    if not from_permacache:
        timer = g.stats.get_timer("promote.get_live.cass")
        timer.start()
        links = set()
        weights = {}
        find_srids = set(srids)
        if '' in find_srids:
            find_srids.remove('')
            find_srids.add(SponsorBoxWeightings.FRONT_PAGE)
        ads = SponsorBoxWeightings.load_multi(find_srids)
        for srid, refs in ads.iteritems():
            links.update(ref.data['link'] for ref in refs)
            promos = [ref.to_promo() for ref in refs]
            if srid == SponsorBoxWeightings.FRONT_PAGE:
                srid = ''
            elif srid == SponsorBoxWeightings.ALL_ADS_ID:
                srid = 'all'
            weights[srid] = promos
        timer.stop()
    else:
        timer = g.stats.get_timer("promote.get_live.permacache")
        timer.start()
        links, weights = g.permacache.get(promotion_key()) or (set(), {})
        timer.stop()
    return links, weights