How can I run this code once so that my generated post title doesn’t keep changing on publish/update?

function transaction_title( $title )
{


    if ( 'transaction' == get_current_screen()->post_type && '' == $title )
    {
        return 'Transaction '.uniqid();
    }
    // else return the normal title
    else 
    {
        return $title;
    }
}
add_filter( 'title_save_pre', 'transaction_title' );