def do_clean_thread(cursor=None): thq = ThreadIndex.all(keys_only=True) thq.filter("post_count", 1) if cursor: thq.with_cursor(cursor) thread_idx = thq.get() if not thread_idx: logging.info("stop thread clean") return thread = db.get(thread_idx.parent()) if thread: board = Board.get_by_key_name(thread.board) if len(thread.posts) == 1: db.delete(thread) else: logging.error("crap, post count %d, %r" % (len(thread.posts), thread_idx)) else: logging.error("crap, no thread for %r" % thread_idx) deferred.defer(do_clean_thread, thq.cursor())
def do_clean(cursor=None): bq = BlobInfo.all() if cursor: bq.with_cursor(cursor) blob = bq.get() if not blob: return key = str(blob.key()) thq = ThreadIndex.all(keys_only=True) thq.filter("images", key) th = thq.get() if th: logging.info("thread: %r" % th) else: logging.info("no thread for image %r" % key) blob.delete() deferred.defer(do_clean, bq.cursor(), _countdown=30)
def thread_lookup(th, board): thq = ThreadIndex.all(keys_only=True) thq.filter("board", board) thq.filter("post_numbers", int(th)) thread = thq.get() if not thread: return _board, _thread = thread.parent().name().split('/') return int(_thread)