def _limit(query, hints):
    """Apply a limit to a query.

    :param query: query to apply filters to
    :param hints: contains the list of filters and limit details.

    :returns: query updated with any limits satisfied

    """
    if hints.limit:
        original_len = query.count()
        limit_query = query.limit(hints.limit['limit'])
        if limit_query.count() < original_len:
            hints.limit['truncated'] = True
            query = limit_query
    return query
