def METHOD_NAME(self, limit=100, action=None, show_obj=None):
    """
    :param limit: The maximum number of elements to return
    :param action: The type of action to filter in the history. Either 'downloaded' or 'snatched'. Anything else or
                    no value will return everything (up to ``limit``)
    :return: The last ``limit`` elements of type ``action`` in the history
    """
    # TODO: Make this a generator instead
    # TODO: Split compact and detailed into separate methods
    # TODO: Add a date limit as well
    # TODO: Clean up history.mako
    parsed_action = History._get_action(action)
    limit = max(try_int(limit), 0)
    common_sql = (
        'SELECT show_name, h.indexer_id, showid AS show_id, season, episode, action, h.quality, '
        'provider, resource, date, h.proper_tags, h.manually_searched '
        'FROM history h, tv_shows s '
        'WHERE h.showid = s.indexer_id AND h.indexer_id = s.indexer '
    )
    filter_sql = 'AND action = ? '
    order_sql = 'ORDER BY date DESC '
    show_params = []
    if show_obj:
        filter_sql += 'AND s.showid = ? AND s.indexer_id = ?'
        show_params += [show_obj.series_id, show_obj.indexer]
    if parsed_action:
        sql_results = self.db.select(common_sql + filter_sql + order_sql,
                                     [parsed_action] + show_params)
    else:
        sql_results = self.db.select(common_sql + order_sql, show_params)
    detailed = []
    compact = dict()
    # TODO: Convert to a defaultdict and compact items as needed
    # TODO: Convert to using operators to combine items
    for row in sql_results:
        row = History.Item(**row)
        if not limit or len(detailed) < limit:
            detailed.append(row)
        if row.index in compact:
            compact[row.index].actions.append(row.cur_action)
        elif not limit or len(compact) < limit:
            compact[row.index] = row.compacted()
    results = namedtuple('results', ['detailed', 'compact'])
    return results(detailed, list(itervalues(compact)))