Add index for git (#13133)
This commit is contained in:
parent
29bafc4592
commit
3a22cda148
|
|
@ -187,7 +187,7 @@ public class DatabaseChangelog {
|
||||||
* Also, please check out the following blog on how to best create indexes :
|
* Also, please check out the following blog on how to best create indexes :
|
||||||
* https://emptysqua.re/blog/optimizing-mongodb-compound-indexes/
|
* https://emptysqua.re/blog/optimizing-mongodb-compound-indexes/
|
||||||
*/
|
*/
|
||||||
private static Index makeIndex(String... fields) {
|
public static Index makeIndex(String... fields) {
|
||||||
if (fields.length == 1) {
|
if (fields.length == 1) {
|
||||||
return new Index(fields[0], Sort.Direction.ASC).named(fields[0]);
|
return new Index(fields[0], Sort.Direction.ASC).named(fields[0]);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -203,14 +203,14 @@ public class DatabaseChangelog {
|
||||||
* Given a MongockTemplate, a domain class and a bunch of Index definitions, this pure utility function will ensure
|
* Given a MongockTemplate, a domain class and a bunch of Index definitions, this pure utility function will ensure
|
||||||
* those indexes on the database behind the MongockTemplate instance.
|
* those indexes on the database behind the MongockTemplate instance.
|
||||||
*/
|
*/
|
||||||
private static void ensureIndexes(MongockTemplate mongoTemplate, Class<?> entityClass, Index... indexes) {
|
public static void ensureIndexes(MongockTemplate mongoTemplate, Class<?> entityClass, Index... indexes) {
|
||||||
IndexOperations indexOps = mongoTemplate.indexOps(entityClass);
|
IndexOperations indexOps = mongoTemplate.indexOps(entityClass);
|
||||||
for (Index index : indexes) {
|
for (Index index : indexes) {
|
||||||
indexOps.ensureIndex(index);
|
indexOps.ensureIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dropIndexIfExists(MongockTemplate mongoTemplate, Class<?> entityClass, String name) {
|
public static void dropIndexIfExists(MongockTemplate mongoTemplate, Class<?> entityClass, String name) {
|
||||||
try {
|
try {
|
||||||
mongoTemplate.indexOps(entityClass).dropIndex(name);
|
mongoTemplate.indexOps(entityClass).dropIndex(name);
|
||||||
} catch (UncategorizedMongoDbException ignored) {
|
} catch (UncategorizedMongoDbException ignored) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ package com.appsmith.server.migrations;
|
||||||
|
|
||||||
import com.appsmith.external.models.Datasource;
|
import com.appsmith.external.models.Datasource;
|
||||||
import com.appsmith.external.models.Property;
|
import com.appsmith.external.models.Property;
|
||||||
|
import com.appsmith.external.models.QBaseDomain;
|
||||||
import com.appsmith.external.models.QDatasource;
|
import com.appsmith.external.models.QDatasource;
|
||||||
|
import com.appsmith.server.constants.FieldName;
|
||||||
|
import com.appsmith.server.domains.ActionCollection;
|
||||||
import com.appsmith.server.domains.Application;
|
import com.appsmith.server.domains.Application;
|
||||||
import com.appsmith.server.domains.ApplicationPage;
|
import com.appsmith.server.domains.ApplicationPage;
|
||||||
import com.appsmith.server.domains.NewAction;
|
import com.appsmith.server.domains.NewAction;
|
||||||
|
|
@ -35,6 +38,9 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.appsmith.server.migrations.DatabaseChangelog.dropIndexIfExists;
|
||||||
|
import static com.appsmith.server.migrations.DatabaseChangelog.ensureIndexes;
|
||||||
|
import static com.appsmith.server.migrations.DatabaseChangelog.makeIndex;
|
||||||
import static com.appsmith.server.repositories.BaseAppsmithRepositoryImpl.fieldName;
|
import static com.appsmith.server.repositories.BaseAppsmithRepositoryImpl.fieldName;
|
||||||
import static java.lang.Boolean.TRUE;
|
import static java.lang.Boolean.TRUE;
|
||||||
import static org.springframework.data.mongodb.core.query.Criteria.where;
|
import static org.springframework.data.mongodb.core.query.Criteria.where;
|
||||||
|
|
@ -701,4 +707,43 @@ public class DatabaseChangelog2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This migration introduces indexes on newAction, actionCollection, newPage to improve the query performance for
|
||||||
|
* queries like getResourceByDefaultAppIdAndGitSyncId which excludes the deleted entries.
|
||||||
|
*/
|
||||||
|
@ChangeSet(order = "007", id = "update-git-indexes", author = "")
|
||||||
|
public void addIndexesForGit(MongockTemplate mongockTemplate) {
|
||||||
|
|
||||||
|
dropIndexIfExists(mongockTemplate, NewAction.class, "defaultApplicationId_gitSyncId_compound_index");
|
||||||
|
dropIndexIfExists(mongockTemplate, ActionCollection.class, "defaultApplicationId_gitSyncId_compound_index");
|
||||||
|
|
||||||
|
String defaultResources = fieldName(QBaseDomain.baseDomain.defaultResources);
|
||||||
|
ensureIndexes(mongockTemplate, ActionCollection.class,
|
||||||
|
makeIndex(
|
||||||
|
defaultResources + "." + FieldName.APPLICATION_ID,
|
||||||
|
fieldName(QBaseDomain.baseDomain.gitSyncId),
|
||||||
|
fieldName(QBaseDomain.baseDomain.deleted)
|
||||||
|
)
|
||||||
|
.named("defaultApplicationId_gitSyncId_deleted_compound_index")
|
||||||
|
);
|
||||||
|
|
||||||
|
ensureIndexes(mongockTemplate, NewAction.class,
|
||||||
|
makeIndex(
|
||||||
|
defaultResources + "." + FieldName.APPLICATION_ID,
|
||||||
|
fieldName(QBaseDomain.baseDomain.gitSyncId),
|
||||||
|
fieldName(QBaseDomain.baseDomain.deleted)
|
||||||
|
)
|
||||||
|
.named("defaultApplicationId_gitSyncId_deleted_compound_index")
|
||||||
|
);
|
||||||
|
|
||||||
|
ensureIndexes(mongockTemplate, NewPage.class,
|
||||||
|
makeIndex(
|
||||||
|
defaultResources + "." + FieldName.APPLICATION_ID,
|
||||||
|
fieldName(QBaseDomain.baseDomain.gitSyncId),
|
||||||
|
fieldName(QBaseDomain.baseDomain.deleted)
|
||||||
|
)
|
||||||
|
.named("defaultApplicationId_gitSyncId_deleted_compound_index")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user