Skip to content

Commit feb942e

Browse files
committed
change horizontalScaling db option
1 parent 74d3d86 commit feb942e

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

spec/MongoStorageAdapter.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
557557
horizontalScaling: true,
558558
databaseAdapter: adapter,
559559
});
560-
expect(adapter.horizontalScaling).toBe(true);
560+
expect(adapter.enableHooks).toBe(true);
561561
spyOn(adapter, '_onchange');
562562
const schema = {
563563
fields: {

spec/PostgresStorageAdapter.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,20 +392,22 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
392392
});
393393

394394
it('should watch _SCHEMA changes', async () => {
395+
const enableHooks = true;
395396
await reconfigureServer({
396397
horizontalScaling: true,
397398
});
398399
const { database } = Config.get(Parse.applicationId);
399400
const { adapter } = database;
400-
expect(adapter.horizontalScaling).toBe(true);
401+
expect(adapter.enableHooks).toBe(enableHooks);
401402
spyOn(adapter, '_onchange');
402403

403404
const otherInstance = new PostgresStorageAdapter({
404405
uri: databaseURI,
405406
collectionPrefix: '',
406-
databaseOptions: { horizontalScaling: true },
407+
databaseOptions: {},
408+
enableHooks,
407409
});
408-
expect(otherInstance.horizontalScaling).toBe(true);
410+
expect(otherInstance.enableHooks).toBe(enableHooks);
409411
otherInstance._listenToSchema();
410412

411413
await otherInstance.createClass('Stuff', {

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,14 @@ export class MongoStorageAdapter implements StorageAdapter {
121121
client: MongoClient;
122122
_maxTimeMS: ?number;
123123
canSortOnJoinTables: boolean;
124-
horizontalScaling: boolean;
125-
126-
constructor({ uri = defaults.DefaultMongoURI, collectionPrefix = '', mongoOptions = {} }: any) {
124+
enableHooks: boolean;
125+
126+
constructor({
127+
uri = defaults.DefaultMongoURI,
128+
collectionPrefix = '',
129+
mongoOptions = {},
130+
enableHooks = false,
131+
}: any) {
127132
this._uri = uri;
128133
this._collectionPrefix = collectionPrefix;
129134
this._mongoOptions = mongoOptions;
@@ -134,8 +139,7 @@ export class MongoStorageAdapter implements StorageAdapter {
134139
// MaxTimeMS is not a global MongoDB client option, it is applied per operation.
135140
this._maxTimeMS = mongoOptions.maxTimeMS;
136141
this.canSortOnJoinTables = true;
137-
this.horizontalScaling = !!mongoOptions.horizontalScaling;
138-
delete mongoOptions.horizontalScaling;
142+
this.enableHooks = enableHooks;
139143
delete mongoOptions.maxTimeMS;
140144
}
141145

@@ -209,7 +213,7 @@ export class MongoStorageAdapter implements StorageAdapter {
209213
return this.connect()
210214
.then(() => this._adaptiveCollection(MongoSchemaCollectionName))
211215
.then(collection => {
212-
if (!this._stream && this.horizontalScaling) {
216+
if (!this._stream && this.enableHooks) {
213217
this._stream = collection._mongoCollection.watch();
214218
this._stream.on('change', () => this._onchange());
215219
}

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ const buildWhereClause = ({ schema, query, index, caseInsensitive }): WhereClaus
796796

797797
export class PostgresStorageAdapter implements StorageAdapter {
798798
canSortOnJoinTables: boolean;
799-
horizontalScaling: boolean;
799+
enableHooks: boolean;
800800

801801
// Private
802802
_collectionPrefix: string;
@@ -806,10 +806,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
806806
_stream: any;
807807
_uuid: any;
808808

809-
constructor({ uri, collectionPrefix = '', databaseOptions = {} }: any) {
809+
constructor({ uri, collectionPrefix = '', databaseOptions = {}, enableHooks = false }: any) {
810810
this._collectionPrefix = collectionPrefix;
811-
this.horizontalScaling = !!databaseOptions.horizontalScaling;
812-
delete databaseOptions.horizontalScaling;
811+
this.enableHooks = enableHooks;
812+
813813
const { client, pgp } = createClient(uri, databaseOptions);
814814
this._client = client;
815815
this._onchange = () => {};
@@ -843,7 +843,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
843843
}
844844

845845
async _listenToSchema() {
846-
if (!this._stream && this.horizontalScaling) {
846+
if (!this._stream && this.enableHooks) {
847847
this._stream = await this._client.connect({ direct: true });
848848
this._stream.client.on('notification', data => {
849849
const payload = JSON.parse(data.payload);

src/Controllers/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,15 @@ export function getDatabaseController(options: ParseServerOptions): DatabaseCont
154154
throw 'You cannot specify both a databaseAdapter and a databaseURI/databaseOptions/collectionPrefix.';
155155
} else if (!databaseAdapter) {
156156
databaseOptions = databaseOptions || {};
157-
databaseOptions.horizontalScaling = horizontalScaling;
158-
databaseAdapter = getDatabaseAdapter(databaseURI, collectionPrefix, databaseOptions);
157+
databaseAdapter = getDatabaseAdapter(
158+
databaseURI,
159+
collectionPrefix,
160+
databaseOptions,
161+
horizontalScaling
162+
);
159163
} else {
160164
databaseAdapter = loadAdapter(databaseAdapter);
161-
databaseAdapter.horizontalScaling = !!horizontalScaling;
165+
databaseAdapter.enableHooks = !!horizontalScaling;
162166
}
163167
return new DatabaseController(databaseAdapter);
164168
}
@@ -220,7 +224,7 @@ export function getAuthDataManager(options: ParseServerOptions) {
220224
return authDataManager(auth, enableAnonymousUsers);
221225
}
222226

223-
export function getDatabaseAdapter(databaseURI, collectionPrefix, databaseOptions) {
227+
export function getDatabaseAdapter(databaseURI, collectionPrefix, databaseOptions, enableHooks) {
224228
let protocol;
225229
try {
226230
const parsedURI = url.parse(databaseURI);
@@ -234,12 +238,14 @@ export function getDatabaseAdapter(databaseURI, collectionPrefix, databaseOption
234238
uri: databaseURI,
235239
collectionPrefix,
236240
databaseOptions,
241+
enableHooks,
237242
});
238243
default:
239244
return new MongoStorageAdapter({
240245
uri: databaseURI,
241246
collectionPrefix,
242247
mongoOptions: databaseOptions,
248+
enableHooks,
243249
});
244250
}
245251
}

0 commit comments

Comments
 (0)