Improve single schema cache (#7214)

* Initial Commit

* fix flaky test

* temporary set ci timeout

* turn off ci check

* fix postgres tests

* fix tests

* node flaky test

* remove improvements

* Update SchemaPerformance.spec.js

* fix tests

* revert ci

* Create Singleton Object

* properly clear cache testing

* Cleanup

* remove fit

* try PushController.spec

* try push test rewrite

* try push enqueue time

* Increase test timeout

* remove pg server creation test

* xit push tests

* more xit

* remove skipped tests

* Fix conflicts

* reduce ci timeout

* fix push tests

* Revert "fix push tests"

This reverts commit 05aba62f1cbbca7d5d3e80b9444529f59407cb56.

* improve initialization

* fix flaky tests

* xit flaky test

* Update CHANGELOG.md

* enable debug logs

* Update LogsRouter.spec.js

* create initial indexes in series

* lint

* horizontal scaling documentation

* Update Changelog

* change horizontalScaling db option

* Add enableSchemaHooks option

* move enableSchemaHooks to databaseOptions
This commit is contained in:
Diamond Lewis
2021-03-16 16:05:36 -05:00
committed by GitHub
parent 32fc45d2d2
commit a02014f557
38 changed files with 673 additions and 937 deletions

View File

@@ -26,6 +26,8 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
it('schemaUpgrade, upgrade the database schema when schema changes', async done => {
await adapter.deleteAllClasses();
const config = Config.get('test');
config.schemaCache.clear();
await adapter.performInitialization({ VolatileClassesSchemas: [] });
const client = adapter._client;
const className = '_PushStatus';
@@ -232,13 +234,19 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
});
it('should use index for caseInsensitive query', async () => {
await adapter.deleteAllClasses();
const config = Config.get('test');
config.schemaCache.clear();
await adapter.performInitialization({ VolatileClassesSchemas: [] });
const database = Config.get(Parse.applicationId).database;
await database.loadSchema({ clearCache: true });
const tableName = '_User';
const user = new Parse.User();
user.set('username', 'Elmer');
user.set('password', 'Fudd');
await user.signUp();
const database = Config.get(Parse.applicationId).database;
//Postgres won't take advantage of the index until it has a lot of records because sequential is faster for small db's
const client = adapter._client;
@@ -287,12 +295,19 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
});
it('should use index for caseInsensitive query using default indexname', async () => {
await adapter.deleteAllClasses();
const config = Config.get('test');
config.schemaCache.clear();
await adapter.performInitialization({ VolatileClassesSchemas: [] });
const database = Config.get(Parse.applicationId).database;
await database.loadSchema({ clearCache: true });
const tableName = '_User';
const user = new Parse.User();
user.set('username', 'Tweety');
user.set('password', 'Bird');
await user.signUp();
const database = Config.get(Parse.applicationId).database;
const fieldToSearch = 'username';
//Create index before data is inserted
const schema = await new Parse.Schema('_User').get();
@@ -375,6 +390,45 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
});
});
});
it('should watch _SCHEMA changes', async () => {
const enableSchemaHooks = true;
await reconfigureServer({
databaseAdapter: undefined,
databaseURI,
collectionPrefix: '',
databaseOptions: {
enableSchemaHooks,
},
});
const { database } = Config.get(Parse.applicationId);
const { adapter } = database;
expect(adapter.enableSchemaHooks).toBe(enableSchemaHooks);
spyOn(adapter, '_onchange');
enableSchemaHooks;
const otherInstance = new PostgresStorageAdapter({
uri: databaseURI,
collectionPrefix: '',
databaseOptions: { enableSchemaHooks },
});
expect(otherInstance.enableSchemaHooks).toBe(enableSchemaHooks);
otherInstance._listenToSchema();
await otherInstance.createClass('Stuff', {
className: 'Stuff',
fields: {
objectId: { type: 'String' },
createdAt: { type: 'Date' },
updatedAt: { type: 'Date' },
_rperm: { type: 'Array' },
_wperm: { type: 'Array' },
},
classLevelPermissions: undefined,
});
await new Promise(resolve => setTimeout(resolve, 500));
expect(adapter._onchange).toHaveBeenCalled();
});
});
describe_only_db('postgres')('PostgresStorageAdapter shutdown', () => {