<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def db_optimize(name,
              table=None,
              **connection_args):
    '''
    Optimizes the full database or just a given table

    CLI Example:

    .. code-block:: bash

        salt '*' mysql.db_optimize dbname
    '''
    ret = []
    if table is None:
        # we need to optimize all tables
        tables = db_tables(name, **connection_args)
        for table in tables:
            log.info('Optimizing table \'%s\' in db \'%s\'..', name, table)
            ret.append(__optimize_table(name, table, **connection_args))
    else:
        log.info('Optimizing table \'%s\' in db \'%s\'..', name, table)
        ret = __optimize_table(name, table, **connection_args)
    return ret