cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

create_database checks existence twice (3 RTTs) #142

Closed ricellis closed 7 years ago

ricellis commented 8 years ago

I was doing some testing and noticed that the create_database call makes two GET requests before the PUT to create a remote database. This is what happens:

  1. client.create_database() calls database.exists() which does a GET
  2. If it didn't exist client.create_database() calls database.create()
  3. database.create() calls exists() which does another GET
  4. If the database does not exist then database.create() finally does the PUT.

I think it could be beneficial to replace these three round trips with a single request to PUT given that if the database already exists a 412 is returned. There is some complication in that currently database.create() would not throw for the 412 response case, but client.create_database optionally needs to throw.

client.create_database('abc')
alfinkel commented 7 years ago

These are now HEAD calls rather than GET fwiw but imo at least one of the HEAD calls should be removed. See my comments on #279.