def METHOD_NAME(predicate = None, db=None):
	"""
	Recomputes the descendant_count of a large number of comments.
	The descendant_count of a comment is equal to the number of direct visible child comments
	plus the sum of the descendant_count of those visible child comments.
	:param predicate: If set, only update comments matching this predicate
	:param db: If set, use this instead of g.db
	So for example
		>>> bulk_update_descendant_counts()
	will update all comments, while
		>>> bulk_update_descendant_counts(lambda q: q.where(Comment.parent_submission == 32)
	will only update the descendant counts of comments where parent_submission=32
	Internally, how this works is
		1. Find the maximum level of comments matching the predicate
		2. Starting from that level and going down, for each level update the descendant_counts
	Since the comments at the max level will always have 0 children, this means that we will perform
	`level` updates to update all comments.
	The update query looks like
		UPDATE comments
		SET descendant_count=descendant_counts.descendant_count
		FROM (
			SELECT
				parent_comments.id AS id,
				coalesce(sum(child_comments.descendant_count + 1), 0) AS descendant_count
			FROM comments AS parent_comments
				LEFT OUTER JOIN comments AS child_comments ON parent_comments.id = child_comments.parent_comment_id
			GROUP BY parent_comments.id
		) AS descendant_counts
		WHERE comments.id = descendant_counts.id
			AND comments.level = :level_1
			<predicate goes here>
	"""
	db = db if db is not None else g.db
	max_level_query = db.query(func.max(Comment.level))
	if predicate:
		max_level_query = predicate(max_level_query)
	max_level = max_level_query.scalar()
	if max_level is None:
		max_level = 0
	for level in range(max_level, 0, -1):
		parent_comments = alias(Comment, name="parent_comments")
		child_comments = alias(Comment, name="child_comments")
		descendant_counts = aliased(
			Comment,
			(
				select(parent_comments)
				.join(
					child_comments,
					parent_comments.corresponding_column(Comment.id) == child_comments.corresponding_column(Comment.parent_comment_id),
					True
				)
				.group_by(parent_comments.corresponding_column(Comment.id))
				.with_only_columns(
					parent_comments.corresponding_column(Comment.id),
					func.coalesce(
						func.sum(child_comments.corresponding_column(Comment.descendant_count) + text(str(1))),
						text(str(0))
					).label('descendant_count')
				)
				.subquery(name='descendant_counts')
			),
			adapt_on_names=True
		)
		update_statement = (
			update(Comment)
			.values(descendant_count=descendant_counts.descendant_count)
			.execution_options(synchronize_session=False)
			.where(Comment.id == descendant_counts.id)
			.where(Comment.level == level)
		)
		if predicate:
			update_statement = predicate(update_statement)
		db.execute(update_statement)
	db.commit()