Skip to content

Commit

Permalink
loading vocabularies on first request (lazy loading) instead of on
Browse files Browse the repository at this point in the history
start-up
  • Loading branch information
SrdjanStevanetic committed Apr 23, 2024
1 parent 8f96cdf commit 6ddfbfc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@ public class VocabularyRepository {

private static final String ID = "id";

private List<Vocabulary> vocabs = new ArrayList<>();
private List<Vocabulary> europeanaRoles;

public void loadIntoMemory() {
if(vocabs.isEmpty()) {
vocabs.addAll(
public List<Vocabulary> getEuropeanaRoles() {
if(europeanaRoles==null) {
europeanaRoles=new ArrayList<>();
europeanaRoles.addAll(
datastore.find(Vocabulary.class)
.iterator()
.toList());
}
return europeanaRoles;
}

/**
* retrieve records by their id, from the in-memory collection
* @param vocabularyIds
* @return
*/
public List<Vocabulary> findByUri(List<String> vocabularyIds) {
return vocabs.stream()
return getEuropeanaRoles().stream()
.filter(el -> vocabularyIds.contains(el.getId()))
.toList();
}
Expand Down Expand Up @@ -87,4 +89,5 @@ public void dropCollection() {
public long countRecords() {
return datastore.find(Vocabulary.class).count();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void ensureDatabaseInitialization() throws ApplicationInitializationExcep
}
vocabRepository.saveBulk(roles);
}
vocabRepository.loadIntoMemory();
}

@Bean(name = BEAN_EM_DATA_SOURCES)
Expand Down

0 comments on commit 6ddfbfc

Please sign in to comment.