metricq / aiocouch

🛋 An asynchronous client library for CouchDB 2.x and 3.x
https://aiocouch.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
29 stars 10 forks source link

Remove a HTTP call on Database.create(exists_ok=True) #12

Closed adrienverge closed 4 years ago

adrienverge commented 4 years ago

Currently, the problem of db.create("id", exists_ok=True) is that it adds a useless HTTP call if the file already exists:

await doc._exists()       HEAD /db/id       200 OK
await doc.fetch()         GET /db/id        200 OK

I propose to remove the first (useless) HEAD request when we're sure we want to get the full document (exists_ok=True). And keep the lightweight HEAD request when we don't care about its contents (exists_ok=False).