Futzing with read preference (#3963)
* allow setting readpreference when using rest api. * take out partially complete unit test. * oops. nit * Include read preference option for find directly from api and adding few more tests * Adding catch for all tests * Keep same check for get and find * Turn read preference case insensitive * Includes and subqueries read preferences through API * Fixing bugs regarding changes that were done in master branch during the last year * Changing behavior to make includeReadPreference and subqueryReadPreference to follow readPreference by default
This commit is contained in:
committed by
GitHub
parent
893f1d376e
commit
afa74d655d
@@ -41,16 +41,12 @@ describe('GridFSBucket and GridStore interop', () => {
|
|||||||
expect(gfsResult.toString('utf8')).toBe(twoMegabytesFile);
|
expect(gfsResult.toString('utf8')).toBe(twoMegabytesFile);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(
|
it('properly deletes a file from GridFS', async () => {
|
||||||
'properly deletes a file from GridFS',
|
const gfsAdapter = new GridFSBucketAdapter(databaseURI);
|
||||||
async () => {
|
await gfsAdapter.createFile('myFileName', 'a simple file');
|
||||||
const gfsAdapter = new GridFSBucketAdapter(databaseURI);
|
await gfsAdapter.deleteFile('myFileName');
|
||||||
await gfsAdapter.createFile('myFileName', 'a simple file');
|
await expectMissingFile(gfsAdapter, 'myFileName');
|
||||||
await gfsAdapter.deleteFile('myFileName');
|
}, 1000000);
|
||||||
await expectMissingFile(gfsAdapter, 'myFileName');
|
|
||||||
},
|
|
||||||
1000000
|
|
||||||
);
|
|
||||||
|
|
||||||
it('properly overrides files', async () => {
|
it('properly overrides files', async () => {
|
||||||
const gfsAdapter = new GridFSBucketAdapter(databaseURI);
|
const gfsAdapter = new GridFSBucketAdapter(databaseURI);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -926,6 +926,9 @@ export class MongoStorageAdapter implements StorageAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_parseReadPreference(readPreference: ?string): ?string {
|
_parseReadPreference(readPreference: ?string): ?string {
|
||||||
|
if (readPreference) {
|
||||||
|
readPreference = readPreference.toUpperCase();
|
||||||
|
}
|
||||||
switch (readPreference) {
|
switch (readPreference) {
|
||||||
case 'PRIMARY':
|
case 'PRIMARY':
|
||||||
readPreference = ReadPreference.PRIMARY;
|
readPreference = ReadPreference.PRIMARY;
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ const AlwaysSelectedKeys = ['objectId', 'createdAt', 'updatedAt', 'ACL'];
|
|||||||
// include
|
// include
|
||||||
// keys
|
// keys
|
||||||
// redirectClassNameForKey
|
// redirectClassNameForKey
|
||||||
|
// readPreference
|
||||||
|
// includeReadPreference
|
||||||
|
// subqueryReadPreference
|
||||||
function RestQuery(
|
function RestQuery(
|
||||||
config,
|
config,
|
||||||
auth,
|
auth,
|
||||||
@@ -362,6 +365,8 @@ RestQuery.prototype.replaceInQuery = function() {
|
|||||||
if (this.restOptions.subqueryReadPreference) {
|
if (this.restOptions.subqueryReadPreference) {
|
||||||
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
||||||
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
||||||
|
} else if (this.restOptions.readPreference) {
|
||||||
|
additionalOptions.readPreference = this.restOptions.readPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
var subquery = new RestQuery(
|
var subquery = new RestQuery(
|
||||||
@@ -421,6 +426,8 @@ RestQuery.prototype.replaceNotInQuery = function() {
|
|||||||
if (this.restOptions.subqueryReadPreference) {
|
if (this.restOptions.subqueryReadPreference) {
|
||||||
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
||||||
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
||||||
|
} else if (this.restOptions.readPreference) {
|
||||||
|
additionalOptions.readPreference = this.restOptions.readPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
var subquery = new RestQuery(
|
var subquery = new RestQuery(
|
||||||
@@ -484,6 +491,8 @@ RestQuery.prototype.replaceSelect = function() {
|
|||||||
if (this.restOptions.subqueryReadPreference) {
|
if (this.restOptions.subqueryReadPreference) {
|
||||||
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
||||||
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
||||||
|
} else if (this.restOptions.readPreference) {
|
||||||
|
additionalOptions.readPreference = this.restOptions.readPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
var subquery = new RestQuery(
|
var subquery = new RestQuery(
|
||||||
@@ -545,6 +554,8 @@ RestQuery.prototype.replaceDontSelect = function() {
|
|||||||
if (this.restOptions.subqueryReadPreference) {
|
if (this.restOptions.subqueryReadPreference) {
|
||||||
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.readPreference = this.restOptions.subqueryReadPreference;
|
||||||
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
additionalOptions.subqueryReadPreference = this.restOptions.subqueryReadPreference;
|
||||||
|
} else if (this.restOptions.readPreference) {
|
||||||
|
additionalOptions.readPreference = this.restOptions.readPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
var subquery = new RestQuery(
|
var subquery = new RestQuery(
|
||||||
@@ -809,6 +820,8 @@ function includePath(config, auth, response, path, restOptions = {}) {
|
|||||||
includeRestOptions.readPreference = restOptions.includeReadPreference;
|
includeRestOptions.readPreference = restOptions.includeReadPreference;
|
||||||
includeRestOptions.includeReadPreference =
|
includeRestOptions.includeReadPreference =
|
||||||
restOptions.includeReadPreference;
|
restOptions.includeReadPreference;
|
||||||
|
} else if (restOptions.readPreference) {
|
||||||
|
includeRestOptions.readPreference = restOptions.readPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryPromises = Object.keys(pointersHash).map(className => {
|
const queryPromises = Object.keys(pointersHash).map(className => {
|
||||||
|
|||||||
@@ -3,7 +3,13 @@ import rest from '../rest';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import Parse from 'parse/node';
|
import Parse from 'parse/node';
|
||||||
|
|
||||||
const ALLOWED_GET_QUERY_KEYS = ['keys', 'include'];
|
const ALLOWED_GET_QUERY_KEYS = [
|
||||||
|
'keys',
|
||||||
|
'include',
|
||||||
|
'readPreference',
|
||||||
|
'includeReadPreference',
|
||||||
|
'subqueryReadPreference',
|
||||||
|
];
|
||||||
|
|
||||||
export class ClassesRouter extends PromiseRouter {
|
export class ClassesRouter extends PromiseRouter {
|
||||||
className(req) {
|
className(req) {
|
||||||
@@ -57,12 +63,21 @@ export class ClassesRouter extends PromiseRouter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof body.keys == 'string') {
|
if (typeof body.keys === 'string') {
|
||||||
options.keys = body.keys;
|
options.keys = body.keys;
|
||||||
}
|
}
|
||||||
if (body.include) {
|
if (body.include) {
|
||||||
options.include = String(body.include);
|
options.include = String(body.include);
|
||||||
}
|
}
|
||||||
|
if (typeof body.readPreference === 'string') {
|
||||||
|
options.readPreference = body.readPreference;
|
||||||
|
}
|
||||||
|
if (typeof body.includeReadPreference === 'string') {
|
||||||
|
options.includeReadPreference = body.includeReadPreference;
|
||||||
|
}
|
||||||
|
if (typeof body.subqueryReadPreference === 'string') {
|
||||||
|
options.subqueryReadPreference = body.subqueryReadPreference;
|
||||||
|
}
|
||||||
|
|
||||||
return rest
|
return rest
|
||||||
.get(
|
.get(
|
||||||
@@ -154,6 +169,9 @@ export class ClassesRouter extends PromiseRouter {
|
|||||||
'includeAll',
|
'includeAll',
|
||||||
'redirectClassNameForKey',
|
'redirectClassNameForKey',
|
||||||
'where',
|
'where',
|
||||||
|
'readPreference',
|
||||||
|
'includeReadPreference',
|
||||||
|
'subqueryReadPreference',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const key of Object.keys(body)) {
|
for (const key of Object.keys(body)) {
|
||||||
@@ -188,6 +206,15 @@ export class ClassesRouter extends PromiseRouter {
|
|||||||
if (body.includeAll) {
|
if (body.includeAll) {
|
||||||
options.includeAll = true;
|
options.includeAll = true;
|
||||||
}
|
}
|
||||||
|
if (typeof body.readPreference === 'string') {
|
||||||
|
options.readPreference = body.readPreference;
|
||||||
|
}
|
||||||
|
if (typeof body.includeReadPreference === 'string') {
|
||||||
|
options.includeReadPreference = body.includeReadPreference;
|
||||||
|
}
|
||||||
|
if (typeof body.subqueryReadPreference === 'string') {
|
||||||
|
options.subqueryReadPreference = body.subqueryReadPreference;
|
||||||
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/vendor/mongodbUrl.js
vendored
16
src/vendor/mongodbUrl.js
vendored
@@ -101,7 +101,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
code === 10 /*\n*/ ||
|
code === 10 /*\n*/ ||
|
||||||
code === 12 /*\f*/ ||
|
code === 12 /*\f*/ ||
|
||||||
code === 160 /*\u00A0*/ ||
|
code === 160 /*\u00A0*/ ||
|
||||||
code === 65279 /*\uFEFF*/;
|
code === 65279; /*\uFEFF*/
|
||||||
if (start === -1) {
|
if (start === -1) {
|
||||||
if (isWs) continue;
|
if (isWs) continue;
|
||||||
lastPos = start = i;
|
lastPos = start = i;
|
||||||
@@ -193,7 +193,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
// how the browser resolves relative URLs.
|
// how the browser resolves relative URLs.
|
||||||
if (slashesDenoteHost || proto || /^\/\/[^@\/]+@[^@\/]+/.test(rest)) {
|
if (slashesDenoteHost || proto || /^\/\/[^@\/]+@[^@\/]+/.test(rest)) {
|
||||||
var slashes =
|
var slashes =
|
||||||
rest.charCodeAt(0) === 47 /*/*/ && rest.charCodeAt(1) === 47 /*/*/;
|
rest.charCodeAt(0) === 47 /*/*/ && rest.charCodeAt(1) === 47; /*/*/
|
||||||
if (slashes && !(proto && hostlessProtocol[proto])) {
|
if (slashes && !(proto && hostlessProtocol[proto])) {
|
||||||
rest = rest.slice(2);
|
rest = rest.slice(2);
|
||||||
this.slashes = true;
|
this.slashes = true;
|
||||||
@@ -285,7 +285,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|||||||
// assume that it's an IPv6 address.
|
// assume that it's an IPv6 address.
|
||||||
var ipv6Hostname =
|
var ipv6Hostname =
|
||||||
hostname.charCodeAt(0) === 91 /*[*/ &&
|
hostname.charCodeAt(0) === 91 /*[*/ &&
|
||||||
hostname.charCodeAt(hostname.length - 1) === 93 /*]*/;
|
hostname.charCodeAt(hostname.length - 1) === 93; /*]*/
|
||||||
|
|
||||||
// validate a little.
|
// validate a little.
|
||||||
if (!ipv6Hostname) {
|
if (!ipv6Hostname) {
|
||||||
@@ -868,11 +868,11 @@ Url.prototype.resolveObject = function(relative) {
|
|||||||
|
|
||||||
// put the host back
|
// put the host back
|
||||||
if (psychotic) {
|
if (psychotic) {
|
||||||
result.hostname = result.host = isAbsolute
|
if (isAbsolute) {
|
||||||
? ''
|
result.hostname = result.host = '';
|
||||||
: srcPath.length
|
} else {
|
||||||
? srcPath.shift()
|
result.hostname = result.host = srcPath.length ? srcPath.shift() : '';
|
||||||
: '';
|
}
|
||||||
//occasionally the auth can get stuck only in host
|
//occasionally the auth can get stuck only in host
|
||||||
//this especially happens in cases like
|
//this especially happens in cases like
|
||||||
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
|
||||||
|
|||||||
Reference in New Issue
Block a user