Public posts – preventing duplicate form submissions

Don’t know if it’s best practice but i had a similar issue and I ended up checking by custom sql query to check if the title already exists in my post type
and filtered duplicate posts and i hooked that to wp_insert_post_data filter hook.

add_filter('wp_insert_post_data','prevente_duplicates');
function prevente_duplicates($data,$postarr){
    $count = $wpdb->get_results($wpdb->prepare("SELECT count(id)
            FROM $wpdb->posts
            WHERE post_type="MY_POST_TYPE_NAME"
            AND post_title="%s"",$data['post_title']));
    if ($count > 0 ){
        return false;
    }
    return $data;
}