Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 67 lines (57 sloc) 2.042 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#!/usr/bin/env python
# coding=utf-8

import os
import re
import time
import datetime
import hashlib
import urllib
import string
import random

from google.appengine.ext import webapp
from google.appengine.api import memcache
from google.appengine.api import urlfetch
from google.appengine.ext import db
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

from v2ex.babel import Member
from v2ex.babel import Counter
from v2ex.babel import Section
from v2ex.babel import Node
from v2ex.babel import Topic
from v2ex.babel import Reply

from v2ex.babel import SYSTEM_VERSION

from v2ex.babel.security import *
from v2ex.babel.ua import *
from v2ex.babel.da import *
from v2ex.babel.ext.cookies import Cookies
from v2ex.babel.ext.sessions import Session

from django.utils import simplejson as json

from mapreduce import operation as op

def tidy_node(entity):
    # Recalculate exact topics counter
    q = db.GqlQuery("SELECT __key__ FROM Topic WHERE node_num = :1", entity.num)
    entity.topics = q.count()
    memcache.set('Node_' + str(entity.num), entity, 86400)
    memcache.set('Node::' + entity.name, entity, 86400)
    yield op.db.Put(entity)
    
def tidy_topic(entity):
    # Recalculate exact replies counter
    q = db.GqlQuery("SELECT __key__ FROM Reply WHERE topic_num = :1", entity.num)
    entity.replies = q.count()
    # Ensure member field is correctly set
    q2 = db.GqlQuery("SELECT * FROM Member WHERE num = :1", entity.member_num)
    if q2.count() == 1:
        entity.member = q2[0]
    memcache.set('Topic_' + str(entity.num), entity, 86400)
    yield op.db.Put(entity)
    
def tidy_reply(entity):
    # Ensure member field is correctly set
    q = db.GqlQuery("SELECT * FROM Member WHERE num = :1", entity.member_num)
    if q.count() == 1:
        entity.member = q[0]
    # Ensure topic field is correctly set
    q2 = db.GqlQuery("SELECT * FROM Topic WHERE num = :1", entity.topic_num)
    if q2.count() == 1:
        entity.topic = q2[0]
    yield op.db.Put(entity)
Something went wrong with that request. Please try again.