Example #1
0
def write_coop_reviews(review, pnm, ctmidscsv):
    ctmidscsv = ctmidscsv or ""
    postnotes = []
    for ctmid in csv_list(ctmidscsv):
        # get cooperative theme
        ctm = cached_get(intz(ctmid), coop.Coop)
        if not ctm:
            logging.info("write_coop_reviews: no Coop " + ctmid)
            continue
        penid = pnm.key().id()
        if not coop.member_level(penid, ctm):
            logging.info("write_coop_reviews: not member of " + ctmid)
            continue
        # get/create theme membic for update and write it to the db
        where = "WHERE ctmid = :1 AND srcrev = :2"
        vq = VizQuery(Review, where, int(ctmid), review.key().id())
        revs = vq.fetch(1, read_policy=db.EVENTUAL_CONSISTENCY, deadline = 10)
        ctmrev = None
        if len(revs) > 0:
            ctmrev = revs[0]
        else:
            ctmrev = Review(penid=penid, revtype=review.revtype)
        debuginfo("    copying source review")
        copy_source_review(review, ctmrev, ctmid)
        mctr.synchronized_db_write(ctmrev)
        logging.info("write_coop_reviews wrote review for: Coop " + ctmid + 
                     " " + ctm.name)
        # update cache, recalculate recent and top membics for theme
        update_profile("coop", ctm, ctmrev, srcrev=review)
        # note the review was posted to this theme
        logging.info("    appending post note")
        postnotes.append(coop_post_note(ctm, ctmrev))
    logging.info("    writing svcdata.postnotes " + str(postnotes))
    write_coop_post_notes_to_svcdata(review, postnotes)
Example #2
0
def write_review(review, pnm, acc):
    set_review_mainfeed(review, acc)
    mctr.synchronized_db_write(review)
    logging.info("write_review wrote Review " + str(review.key().id()))
    # update all related cached data, or clear it for later rebuild
    mfeed.update_feed_caches(review, addifnew=True)
    update_profile("pen", pnm, review)
Example #3
0
def rebuild_membics_block(pct, pgid):
    logging.info("rebuild_membics_block " + pct + " " + str(pgid))
    acc = None
    pco = None
    if pct == "coop":
        pco = coop.Coop.get_by_id(int(pgid))
        if pco and pco.preb and not coop.prebuilt_membics_stale(pco):
            return pco.preb
    elif pct == "pen":
        pco = pen.PenName.get_by_id(int(pgid))
        if pco:
            pen.filter_sensitive_fields(pco)
    if not pco:
        logging.info("rmb " + pct + " " + str(pgid) + " not found")
        return None
    where = "WHERE ctmid = 0 AND penid = :1 ORDER BY modified DESC"
    if pct == "coop":
        where = "WHERE ctmid = :1 ORDER BY modified DESC"
    vq = VizQuery(rev.Review, where, pco.key().id())
    fsz = 100  # 11/30/16 complaint that 50 makes "recent" tab feel lossy
    fmax = fsz
    if pct == "coop":
        fmax = 500
    jstr = ""
    js2 = ""
    membics = vq.fetch(fmax, read_policy=db.EVENTUAL_CONSISTENCY, deadline=60)
    idx = 0  # idx not initialized if enumerate punts due to no membics...
    for idx, membic in enumerate(membics):
        if idx < fsz:
            jstr = rev.append_review_jsoncsv(jstr, membic)
        else:
            js2 = rev.append_review_jsoncsv(js2, membic)
    jstr = append_top20_membics_to_jsoncsv(jstr, membics, pct, pco, 450 * 1024)
    if jstr:
        jstr = "," + jstr;
    jstr = moracct.obj2JSON(pco) + jstr;
    if pct == "coop":
        pco.preb = "[" + jstr + "]"
        pco.preb2 = "[" + js2 + "]"
        coop.update_coop_stats(pco, idx)
        # rebuild preb to include updated stats, maybe s1 off by one but ok.
        pco.preb = "[" + jstr + "]"
        mctr.synchronized_db_write(pco)
    return "[" + jstr + "]"
Example #4
0
def update_profile(cacheprefix, dbprofinst, rev, srcrev=None):
    prc = ProfRevCache(cacheprefix, dbprofinst)
    if len(prc.mainlist) == 0:  # cache uninitialized or no membics yet
        fetch_recent_membics(cacheprefix, dbprofinst.key().id(), prc)
    if srcrev:  # prepend source rev first so it ends up second in the list
        prc.add_instance(srcrev, prepend=True) 
    prc.add_instance(rev, prepend=True)  # ensure new rev instance is cached
    updtop = update_top_membics(cacheprefix, dbprofinst, rev, prc)
    if updtop:
        dbprofinst.top20s = updtop
        dbprofinst = mctr.synchronized_db_write(dbprofinst)
        logging.info("update_profile wrote new top membics for " +
                     cacheprefix + " " + str(dbprofinst.key().id()))
        prc.set_db_prof_inst(dbprofinst)
    if cacheprefix == "coop":
        dbprofinst.preb = prc.cached_value()
        dbprofinst = mctr.synchronized_db_write(dbprofinst)
        logging.info("update_profile updated preb for " +
                     cacheprefix + " " + str(dbprofinst.key().id()))
        # prc.set_db_prof_inst(dbprofinst)  # not necessary
    prc.update_memcache()