Example #1
0
def do_clean_board(cursor=None):
  thq = Board.all()

  if cursor:
    thq.with_cursor(cursor)

  board = thq.get()

  if not board:
    logging.info("stop board clean")
    return

  """
  board_c = BoardCounter(key_name=board.key().name())
  board_c.counter = board._entity.get('counter')
  board_c.put()
  """
  keys = board.linked
  if not keys:
    keys = [ (board.code, th) for th in board.thread]

  threads = Thread.load_list(keys)

  board.linked = [th for (th,data) in zip(keys, threads) if data]
  fill_board(board)

  board.put()
  #Cache.remove("board", board.key().name())

  deferred.defer(do_clean_board, thq.cursor())
Example #2
0
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())
Example #3
0
def do_clean_board(cursor=None):
  thq = Board.all()

  if cursor:
    thq.with_cursor(cursor)

  board = thq.get()

  if not board:
    logging.info("stop board clean")
    return

  threads = Thread.load_list(board.thread, board.key().name())

  board.thread = [th for (th,data) in threads if data]
  board.put()

  deferred.defer(do_clean_board, thq.cursor())
Example #4
0
def do_clean_thread(cursor=None):
  thq = Thread.all(keys_only=True)

  if cursor:
    thq.with_cursor(cursor)

  thread = thq.get()

  if not thread:
    logging.info("stop thread clean")
    return

  board = Board.get(thread.parent())

  if not board or thread.id() not in board.thread:
    db.delete(thread)
    logging.info("purged thread")

  deferred.defer(do_clean_thread, thq.cursor(), _countdown=10)
Example #5
0
def do_clean_thread(cursor=None):
  thq = Thread.all()
  thq.filter("posts_count <", 5)

  if cursor:
    thq.with_cursor(cursor)

  thread = thq.get()

  if not thread:
    logging.info("stop thread clean")
    return

  board = Board.get_by_key_name(thread.board)

  if len(thread.posts) < 5: # FIXME: magic number
    db.delete(thread)
    logging.info("purged thread")
  else:
    assert False, "oops invalid post count"

  deferred.defer(do_clean_thread, thq.cursor())