Skip to content

Commit

Permalink
Database: Workaround COUCHDB-1415 by injecting timestamp in POSTed body.
Browse files Browse the repository at this point in the history
  • Loading branch information
abutcher-gh committed Jul 31, 2024
1 parent 7427e25 commit bfe1c9e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/cradle/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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);
};

//
Expand Down

0 comments on commit bfe1c9e

Please sign in to comment.