def METHOD_NAME(params, instance):
    (is_archived, is_removed, sort) = _comments_params(params)
    # Note: we tried .prefetch_related('content_object')
    # but it gives comment.content_object = None  (Django 1.6)
    types = {t.lower() for t in instance.map_feature_types}
    comments = EnhancedThreadedComment.objects \
        .filter(content_type__model__in=types) \
        .filter(instance=instance) \
        .extra(select={
            'visible_flag_count': 'SELECT COUNT(*) ' +
            'FROM otm_comments_enhancedthreadedcommentflag ' +
            'WHERE otm_comments_enhancedthreadedcommentflag.comment_id = ' +
            'otm_comments_enhancedthreadedcomment.threadedcomment_ptr_id ' +
            'AND not hidden'})\
        .extra(order_by=[sort])
    if is_archived is not None:
        comments = comments.filter(is_archived=is_archived)
    if is_removed is not None:
        comments = comments.filter(is_removed=is_removed)
    return comments