diff --git a/spec/AudienceRouter.spec.js b/spec/AudienceRouter.spec.js index 95178bf37b..94f5f442e6 100644 --- a/spec/AudienceRouter.spec.js +++ b/spec/AudienceRouter.spec.js @@ -130,7 +130,7 @@ describe('AudiencesRouter', () => { }); }); - it_exclude_dbs(['postgres'])('query installations with count = 1', done => { + it('query installations with count = 1 on multiple audiences', done => { const config = Config.get('test'); const androidAudienceRequest = { name: 'Android Users', diff --git a/spec/InstallationsRouter.spec.js b/spec/InstallationsRouter.spec.js index 8e5a80c135..67d5890211 100644 --- a/spec/InstallationsRouter.spec.js +++ b/spec/InstallationsRouter.spec.js @@ -129,7 +129,7 @@ describe('InstallationsRouter', () => { }); }); - it_exclude_dbs(['postgres'])('query installations with count = 1', done => { + it('query installations with count = 1 on multiple devices', done => { const config = Config.get('test'); const androidDeviceRequest = { installationId: '12345678-abcd-abcd-abcd-123456789abc', @@ -166,43 +166,6 @@ describe('InstallationsRouter', () => { }); }); - it_only_db('postgres')('query installations with count = 1', async () => { - const config = Config.get('test'); - const androidDeviceRequest = { - installationId: '12345678-abcd-abcd-abcd-123456789abc', - deviceType: 'android', - }; - const iosDeviceRequest = { - installationId: '12345678-abcd-abcd-abcd-123456789abd', - deviceType: 'ios', - }; - const request = { - config: config, - auth: auth.master(config), - body: {}, - query: { - count: 1, - }, - info: {}, - }; - - const router = new InstallationsRouter(); - await rest.create(config, auth.nobody(config), '_Installation', androidDeviceRequest); - await rest.create(config, auth.nobody(config), '_Installation', iosDeviceRequest); - let res = await router.handleFind(request); - let response = res.response; - expect(response.results.length).toEqual(2); - expect(response.count).toEqual(0); // estimate count is zero - - const pgAdapter = config.database.adapter; - await pgAdapter.updateEstimatedCount('_Installation'); - - res = await router.handleFind(request); - response = res.response; - expect(response.results.length).toEqual(2); - expect(response.count).toEqual(2); - }); - it_exclude_dbs(['postgres'])('query installations with limit = 0 and count = 1', done => { const config = Config.get('test'); const androidDeviceRequest = { diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 0e213a5a8d..dc6c37c82e 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -5275,4 +5275,13 @@ describe('Parse.Query testing', () => { // Validate expect(result.executionStats).not.toBeUndefined(); }); + + it('count objects with master key', async () => { + const obj = new Parse.Object('TestObject'); + const obj2 = new Parse.Object('TestObject'); + await Parse.Object.saveAll([obj, obj2]); + const query = new Parse.Query('TestObject'); + const count = await query.count({ useMasterKey: true }); + expect(count).toBe(2); + }); }); diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 77e20297d0..4d1d365106 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -2048,9 +2048,9 @@ export class PostgresStorageAdapter implements StorageAdapter { if (where.pattern.length > 0 || !estimate) { qs = `SELECT count(*) FROM $1:name ${wherePattern}`; } else { + await this.updateEstimatedCount(className); qs = 'SELECT reltuples AS approximate_row_count FROM pg_class WHERE relname = $1'; } - return this._client .one(qs, values, a => { if (a.approximate_row_count == null || a.approximate_row_count == -1) { @@ -2425,9 +2425,9 @@ export class PostgresStorageAdapter implements StorageAdapter { return Promise.resolve(); } - // Used for testing purposes async updateEstimatedCount(className: string) { - return this._client.none('ANALYZE $1:name', [className]); + return this._client.none('ANALYZE $1:name', [className]) + .catch((e) => console.error(`Error: Failed to ANALYZE ${className}:`, e)); } async createTransactionalSession(): Promise {