def init_number_subscriptions():
    clean_up_subscription()
    users = User.query().fetch()
    for user in users:
        followers = Subscription.query(Subscription.following == user.key).count()
        following = Subscription.query(ancestor = user.key).count()
        memcache.init_followers_number(user.key.id(), followers)
        memcache.init_following_number(user.key.id(), following)
def clean_up_subscription():
    subscriptions = Subscription.query().fetch()
    for subscription in subscriptions:
        if not subscription.key.parent.get():
            subscription.key.delete()
            continue
        if not subscription.following.get():
            subscription.key.delete()