Skip to content
This repository has been archived by the owner on Jul 29, 2021. It is now read-only.

Commit

Permalink
fix: improve perf to retrieve the list of apis and applications
Browse files Browse the repository at this point in the history
  • Loading branch information
brasseld authored and NicolasGeraud committed Jan 11, 2018
1 parent a4326ae commit 8f7a158
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public interface ApiMongoRepository extends MongoRepository<ApiMongo, String> {
@Query("{ groups: {$in: ?0} }")
Set<ApiMongo> findByGroups(List<String> groupIds);

@Query(value = "{}", fields="{'picture': 0}")
List<ApiMongo> findAll();
}


Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
@Repository
public interface UserMongoRepository extends MongoRepository<UserMongo, String> {

@Query("{ '_id' : { $in: ?0} }")
@Query(value = "{ '_id' : { $in: ?0} }", fields = "{'picture': 0}")
Set<UserMongo> findByUsernames(List<String> usernames);

@Query(value = "{}", fields = "{'picture': 0}")
List<UserMongo> findAll();
}


68 changes: 52 additions & 16 deletions src/main/resources/scripts/create-index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,74 @@
// "apis" collection
db.apis.dropIndexes();
db.apis.createIndex( { "visibility" : 1 } );
db.apis.createIndex( { "group" : 1 } );
db.apis.reIndex();

// "applications" collection
db.applications.dropIndexes();
db.applications.createIndex( { "group" : 1 } );
db.applications.createIndex( { "name" : 1 } );
db.applications.createIndex( { "status" : 1 } );
db.applications.reIndex();

// "events" collection
db.events.dropIndexes();
db.events.createIndex( { "type" : 1 } );
db.events.createIndex( { "updatedAt" : 1 } );
db.events.createIndex( { "properties.api_id" : 1 } );
db.events.createIndex( { "properties.api_id":1, "type":1} );
db.events.reIndex();

// "plans" collection
db.plans.dropIndexes();
db.plans.createIndex( { "apis" : 1 } );
db.plans.reIndex();

// "subscriptions" collection
db.subscriptions.dropIndexes();
db.subscriptions.createIndex( { "plan" : 1 } );
db.subscriptions.createIndex( { "application" : 1 } );
db.subscriptions.reIndex();

// "keys" collection
db.keys.dropIndexes();
db.keys.createIndex( { "plan" : 1 } );
db.keys.createIndex( { "application" : 1 } );
db.keys.createIndex( { "updatedAt" : 1 } );
db.keys.createIndex( { "revoked" : 1 } );
db.keys.createIndex( { "plan" : 1 , "revoked" : 1, "updatedAt" : 1 } );
db.pages.createIndex( { "api" : 1 } );
db.memberships.createIndex( {"_id.referenceType":1, "_id.referenceId":1, "type":1} );
db.memberships.createIndex( {"_id.referenceType":1, "_id.userId":1} );
db.memberships.createIndex( {"_id.referenceType":1, "_id.userId":1, "type":1} );
db.memberships.createIndex( {"_id.referenceType":1, "_id.referenceId":1, "roles":1} );
db.roles.createIndex( {"_id.scope": 1 } );
db.audits.createIndex( { "referenceType": 1, "referenceId": 1 } );
db.audits.createIndex( { "createdAt": 1 } );
db.rating.createIndex( { "api" : 1 } );
db.ratingAnswers.createIndex( { "rating" : 1 } );

db.apis.reIndex();
db.applications.reIndex();
db.events.reIndex();
db.plans.reIndex();
db.subscriptions.reIndex();
db.keys.reIndex();

// "pages" collection
db.pages.dropIndexes();
db.pages.createIndex( { "api" : 1 } );
db.pages.reIndex();

// "memberships" collection
db.memberships.dropIndexes();
db.memberships.createIndex( {"_id.referenceId":1, "_id.referenceType":1} );
db.memberships.createIndex( {"_id.referenceId":1, "_id.referenceType":1, "roles":1} );
db.memberships.createIndex( {"_id.userId":1, "_id.referenceType":1} );
db.memberships.createIndex( {"_id.userId":1, "_id.referenceType":1, "roles":1} );
db.memberships.reIndex();

// "roles" collection
db.roles.dropIndexes();
db.roles.createIndex( {"_id.scope": 1 } );
db.roles.reIndex();

// "audits" collection
db.audits.dropIndexes();
db.audits.createIndex( { "referenceType": 1, "referenceId": 1 } );
db.audits.createIndex( { "createdAt": 1 } );
db.audits.reIndex();

// "rating" collection
db.rating.dropIndexes();
db.rating.createIndex( { "api" : 1 } );
db.rating.reIndex();

// "ratingAnswers" collection
db.ratingAnswers.dropIndexes();
db.ratingAnswers.createIndex( { "rating" : 1 } );
db.ratingAnswers.reIndex();

0 comments on commit 8f7a158

Please sign in to comment.