def METHOD_NAME(token_id, limit, user_id=None):
    query = DBSession.query(DocumentVersion.history_metadata_id) \
        .join(HistoryMetaData) \
        .join(Document) \
        .filter(Document.type.notin_([OUTING_TYPE, USERPROFILE_TYPE])) \
        .order_by(desc(DocumentVersion.history_metadata_id))
    # pagination filter
    if token_id is not None:
        query = query.filter(DocumentVersion.history_metadata_id < token_id)
    if user_id is not None:
        query = query.filter(HistoryMetaData.user_id == user_id)
    return query.limit(limit).all()