Example #1
0
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 = Thread.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)
Example #2
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 #3
0
def fill_board(board):
  threads = Thread.all(keys_only=True)
  threads.filter("board", board)
  threads.order("-__key__")

  for thread in threads.fetch(TMAX):

    if len(board.thread) >= TMAX:
      return

    if thread.id() not in board.thread:
      board.thread.append(  thread.id() )
Example #4
0
def fill_board(board):
  logging.info("fill board %s" % board.code)
  threads = Thread.all()
  threads.filter("boards", board.code)
  threads.order("-id")

  for thread in threads.fetch(TMAX):

    logging.info("here is thread %r" % thread)

    if len(board.linked) >= TMAX:
      return

    if (thread.board,thread.id) not in board.linked:
      logging.info("add now")
      board.linked.append( (thread.board,thread.id) )
Example #5
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 #6
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 #7
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())