dolthub / dolthub-issues

Issues for dolthub.com
https://dolthub.com
4 stars 1 forks source link

Rapid successive calls to the write API return success but some don't actually succeed #496

Open timsehn opened 1 year ago

timsehn commented 1 year ago

image

image

timsehn commented 1 year ago

So the idea here is that you can't have two write operations going at the same time, so you have to hit the write url with your operationName and see if it is done before you can start another.

Here is the code in Google AppScript:

  var url = 'https://www.dolthub.com/api/v1alpha1/timsehn/google_sheets/write/main/branch?q=' 
    + encodeURIComponent(query);
  var token = 'dhat.v1.a0d6k79cnr88q7pvc6lmjpva7olqff3ioufjb6qnem59kkksdc4g'

  var options = {
    "method": "post",
    "headers": {
      "authorization": token
    }
  }

  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response);

  var responseJSON = JSON.parse(response);

  var operationName = responseJSON.operation_name;
  options = {
    "headers": {
      "authorization": token
    }
  }

  url = 'https://www.dolthub.com/api/v1alpha1/timsehn/google_sheets/write?operationName=' + 
    encodeURIComponent(operationName);

  var isDone = false;

  while ( !isDone ) {
    response = UrlFetchApp.fetch(url, options);
    Logger.log(response)
    responseJSON = JSON.parse(response)
    isDone = responseJSON.done;
  }

I think this API would be better if you could queue up some writes so I'm switching this to an enhancement.