Skip to content

Commit f4ff8b3

Browse files
Merge pull request #448 from Breeding-Insight/feature/BI-2579
[BI-2579] Refresh cache after import completes
2 parents 9b54794 + 438ee08 commit f4ff8b3

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ private Map<String, BrAPIGermplasm> fetchProgramGermplasm(UUID programId) throws
162162
}
163163
}
164164

165+
public void repopulateGermplasmCacheForProgram(UUID programId) {
166+
programGermplasmCache.populate(programId);
167+
}
168+
165169
/**
166170
* Process germplasm into a format for display
167171
* @param programGermplasm
@@ -310,11 +314,8 @@ public List<BrAPIGermplasm> createBrAPIGermplasm(List<BrAPIGermplasm> postBrAPIG
310314
var program = programDAO.fetchOneById(programId);
311315
try {
312316
if (!postBrAPIGermplasmList.isEmpty()) {
313-
Callable<Map<String, BrAPIGermplasm>> postFunction = () -> {
314317
List<BrAPIGermplasm> postResponse = brAPIDAOUtil.post(postBrAPIGermplasmList, upload, api::germplasmPost, importDAO::update);
315-
return processGermplasmForDisplay(postResponse, program.getKey());
316-
};
317-
return programGermplasmCache.post(programId, postFunction);
318+
return new ArrayList<>(processGermplasmForDisplay(postResponse, program.getKey()).values());
318319
}
319320
return new ArrayList<>();
320321
} catch (Exception e) {

src/main/java/org/breedinginsight/brapps/importer/services/processors/germplasm/GermplasmProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ public void postBrapiData(Map<Integer, PendingImport> mappedBrAPIImport, Program
635635
try {
636636
// Create germplasm list
637637
brAPIListDAO.createBrAPILists(List.of(importList), program.getId(), upload);
638+
// Now that we have finished uploading, fetch all the data posted to BrAPI to the cache so it is up-to-date.
639+
brAPIGermplasmDAO.repopulateGermplasmCacheForProgram(program.getId());
638640
} catch (ApiException e) {
639641
throw new InternalServerException(e.toString(), e);
640642
}

src/main/resources/brapi/properties/application.properties

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,25 @@ spring.datasource.password=${BRAPI_DB_PASSWORD}
2525

2626
spring.datasource.driver-class-name=org.postgresql.Driver
2727

28+
# This property when set to true makes it so that a DB transaction is open through the body of a request, nullifying the use of @Transactional.
29+
# It is generally recommended that this be set to false, and methods are properly annotated and release the transactions when complete.
30+
# However, many of the endpoints already rely on this kind of connection infrastructure and changing is more trouble than it's worth.
31+
spring.jpa.open-in-view=true
32+
33+
spring.jpa.properties.hibernate.jdbc.batch_size=50
34+
spring.jpa.properties.hibernate.order_inserts=true
35+
spring.jpa.properties.hibernate.order_updates=true
36+
spring.jpa.hibernate.ddl-auto=validate
37+
38+
# Use these to help debug queries.
39+
# The stats will tell you how long hibernate transactions are taking, how many queries occur, how many entities are being flushed/accessed, etc.
40+
spring.jpa.show-sql=false
41+
spring.jpa.properties.hibernate.generate_statistics=false
42+
2843
spring.flyway.locations=classpath:db/migration,classpath:db/sql,classpath:org/brapi/test/BrAPITestServer/db/migration
2944
spring.flyway.schemas=public
3045
spring.flyway.baselineOnMigrate=true
3146

32-
spring.jpa.hibernate.ddl-auto=validate
33-
spring.jpa.show-sql=false
34-
3547
spring.mvc.dispatch-options-request=true
3648

3749
security.oidc_discovery_url=https://example.com/auth/.well-known/openid-configuration

0 commit comments

Comments
 (0)