Skip to content

Commit 04eb831

Browse files
committed
get indexes on startup
1 parent ec2c0cb commit 04eb831

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

spec/schemas.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,4 +2297,24 @@ describe('schemas', () => {
22972297
});
22982298
})
22992299
});
2300+
2301+
it_exclude_dbs(['postgres'])('get indexes on startup', (done) => {
2302+
const obj = new Parse.Object('TestObject');
2303+
obj.save().then(() => {
2304+
return reconfigureServer({
2305+
appId: 'test',
2306+
restAPIKey: 'test',
2307+
publicServerURL: 'http://localhost:8378/1',
2308+
});
2309+
}).then(() => {
2310+
request.get({
2311+
url: 'http://localhost:8378/1/schemas/TestObject',
2312+
headers: masterKeyHeaders,
2313+
json: true,
2314+
}, (error, response, body) => {
2315+
expect(body.indexes._id_).toBeDefined();
2316+
done();
2317+
});
2318+
});
2319+
});
23002320
});

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,25 @@ export class MongoStorageAdapter {
545545
return this._adaptiveCollection(className)
546546
.then(collection => collection._mongoCollection.dropIndexes());
547547
}
548+
549+
updateSchemaWithIndexes() {
550+
return this.getAllClasses()
551+
.then((classes) => {
552+
const promises = classes.map((schema) => {
553+
return this.getIndexes(schema.className).then((indexes) => {
554+
indexes = indexes.reduce((obj, index) => {
555+
obj[index.name] = index.key;
556+
return obj;
557+
}, {});
558+
return this._schemaCollection()
559+
.then(schemaCollection => schemaCollection.updateSchema(schema.className, {
560+
$set: { _metadata: { indexes: indexes } }
561+
}));
562+
});
563+
});
564+
return Promise.all(promises);
565+
});
566+
}
548567
}
549568

550569
export default MongoStorageAdapter;

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,10 @@ export class PostgresStorageAdapter {
14661466
const qs = 'SELECT * FROM pg_indexes WHERE tablename = ${className}';
14671467
return this._client.any(qs, {className});
14681468
}
1469+
1470+
updateSchemaWithIndexes() {
1471+
return Promise.resolve();
1472+
}
14691473
}
14701474

14711475
function convertPolygonToSQL(polygon) {

src/Controllers/DatabaseController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,11 @@ DatabaseController.prototype.performInitialization = function() {
10051005
throw error;
10061006
});
10071007

1008+
const indexPromise = this.adapter.updateSchemaWithIndexes();
1009+
10081010
// Create tables for volatile classes
10091011
const adapterInit = this.adapter.performInitialization({ VolatileClassesSchemas: SchemaController.VolatileClassesSchemas });
1010-
return Promise.all([usernameUniqueness, emailUniqueness, roleUniqueness, adapterInit]);
1012+
return Promise.all([usernameUniqueness, emailUniqueness, roleUniqueness, adapterInit, indexPromise]);
10111013
}
10121014

10131015
function joinTableName(className, key) {

0 commit comments

Comments
 (0)