title: WordPress - Duplicate entry for Primary Key when updating post meta via concurrent AJAX calls
body: <p>I'm using <a href="https://github.com/A5hleyRich/wp-background-processing" rel="nofollow">Async Request</a> to update WordPress post meta in a loop.</p>
  
  <p>Some people using my code are telling me that it errors, and in their logs, they're finding things like:</p>
  
  <blockquote>
    <p>[Fri Sep 30 15:12:28.782842 2016] [:error] [pid 19006] [client
    127.0.0.1:57559] WordPress database error Duplicate entry '296520' for key 'PRIMARY' for query INSERT INTO <code>wp_postmeta</code> (<code>post_id</code>,
    <code>meta_key</code>, <code>meta_value</code>) VALUES (7637, 'my_titles',
    'a:1:{i:0;O:19:\"My_Title_Item\":8:{s:25:\"\0My_Title_Item\0text\";s:90:\"User
    text\";s:35:\"\0My_Title_Item\0start_datetime\";O:8:\"DateTime\":3:{s:4:\"date\";s:19:\"2016-09-29
    11:28:58\";s:13:\"timezone_type\";i:3;s:8:\"timezone\";s:3:\"UTC\";}s:33:\"\0My_Title_Item\0end_datetime\";b:0;s:27:\"\0My_Title_Item\0pre_my\";b:1;s:24:\"\0My_Title_Item\0uid\";s:10:\"6971607559\";s:35:\"\0My_Title_Item\0visits_per_day\";N;s:27:\"\0My_Title_Item\0errors\";b:0;s:7:\"updated\";O:8:\"DateTime\":3:{s:4:\"date\";s:19:\"2016-09-30
    15:12:15\";s:13:\"timezone_type\";i:3;s:8:\"timezone\";s:3:\"UTC\";}}}')
    made by do_action('wp_ajax_nopriv_wp_my_patch_my_async'),
    call_user_func_array, WP_Async_Request->maybe_handle,
    My_Patch_YR->handle, My_Title_History->__construct,
    My_Title_History->maybe_initialise_titles,
    My_Title_History->get_titles, My_Title_History->maybe_reset_errors,
    My_Title_History->reset_errors_on_latest_title,
    My_Title_History->save_titles_db, update_post_meta, update_metadata,
    add_metadata, referer:
    <a href="https://samplesite.com/wp-admin/admin-ajax.php?action=wp_my_patch_my_async&amp;nonce=068b8bd7f8" rel="nofollow">https://samplesite.com/wp-admin/admin-ajax.php?action=wp_my_patch_my_async&amp;nonce=068b8bd7f8</a></p>
  </blockquote>
  
  <p>The important part being <code>WordPress database error Duplicate entry '296520' for key 'PRIMARY' for query....</code>.</p>
  
  <p>I believe this is happening because the asynchronous code execution is achieved via <code>wp_ajax</code>, and I wonder if it's running multiple requests concurrently?</p>
  
  <p>Is there a way, therefore, to make sure that the key is incremented when running this (if I replace <code>update_post_meta</code> with a direct <code>$wpdb</code> <code>INSERT</code> command) ?</p>
  
  <p>Thanks!</p>