Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRUNK-6162: Speed up startup by eliminating redundant calls to getUnrunDatabaseChanges #4572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions api/src/main/java/org/openmrs/util/DatabaseUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class DatabaseUpdater {

private static final ChangeLogVersionFinder changeLogVersionFinder;

private static final Map<String, List<OpenMRSChangeSet>> cachedUnrunChanges = new HashMap<>();

private static LiquibaseProvider liquibaseProvider;

static {
Expand Down Expand Up @@ -645,7 +647,7 @@ public static List<OpenMRSChangeSet> getUnrunDatabaseChanges(LiquibaseProvider l
return getUnrunDatabaseChanges(liquibaseUpdateFilenames.toArray(new String[0]));
}

return new ArrayList<OpenMRSChangeSet>();
return new ArrayList<>();
}

/**
Expand All @@ -669,15 +671,22 @@ public static List<OpenMRSChangeSet> getUnrunDatabaseChanges(String... changeLog
List<OpenMRSChangeSet> results = new ArrayList<>();

for (String changelogFile : changeLogFilenames) {
if(cachedUnrunChanges.containsKey(changelogFile)) {
results.addAll(cachedUnrunChanges.get(changelogFile));
continue;
}
Liquibase liquibase = getLiquibase(changelogFile, null);
database = liquibase.getDatabase();

List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(new Contexts(CONTEXT), new LabelExpression());


List<OpenMRSChangeSet> changeSetList = new ArrayList<>();
for (ChangeSet changeSet : changeSets) {
OpenMRSChangeSet omrschangeset = new OpenMRSChangeSet(changeSet, database);
results.add(omrschangeset);
changeSetList.add(omrschangeset);
}
cachedUnrunChanges.put(changelogFile, changeSetList);
results.addAll(changeSetList);
}

return results;
Expand Down