From bfe1c9e07a1a51d63a15d3ccdf0bafd649d4ec2a Mon Sep 17 00:00:00 2001 From: Adam Butcher Date: Wed, 31 Jul 2024 23:05:28 +0100 Subject: [PATCH] Database: Workaround COUCHDB-1415 by injecting timestamp in POSTed body. --- lib/cradle/database/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/cradle/database/index.js b/lib/cradle/database/index.js index d40b26f..68c8f4b 100644 --- a/lib/cradle/database/index.js +++ b/lib/cradle/database/index.js @@ -10,6 +10,10 @@ var Database = exports.Database = function (name, connection, opts) { this.opts.cache = false; this.opts.cacheSize = 0; } + + // Workaround https://issues.apache.org/jira/browse/COUCHDB-1415 by default + this.workaroundBug1415 = true; + this.cache = new (cradle.Cache)(this.opts); this.cacheFeed = null; if (this.opts.cache === 'follow') { @@ -47,6 +51,11 @@ Database.prototype.configureCacheFeed = function () { // A wrapper around `Connection.request`, // which prepends the database name. Database.prototype.query = function (options, callback) { + + // XXX: Workaround https://issues.apache.org/jira/browse/COUCHDB-1415 + if (options.body && options.method === 'POST' && this.workaroundBug1415) + options.body.$ts = Date.now(); + options.path = [this.name, options.path].filter(Boolean).join('/'); return this.connection.request(options, callback); }; @@ -88,12 +97,12 @@ Database.prototype.create = function (callback) { Database.prototype.destroy = function (callback) { if (arguments.length > 1) { throw new(Error)("destroy() doesn't take any additional arguments"); - } - + } + this.query({ - method: 'DELETE', - path: '/', - }, callback); + method: 'DELETE', + path: '/', + }, callback); }; //