Skip to content

Commit

Permalink
Merge pull request #324 from europeana/EA-3824-load-vocabs-into-memory
Browse files Browse the repository at this point in the history
load vocabularies into memory
  • Loading branch information
gsergiu authored Apr 23, 2024
2 parents 659ec68 + 9d4d0c7 commit 7ae0775
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,39 @@ public class VocabularyRepository {
Datastore datastore;

private static final String ID = "id";

private List<Vocabulary> europeanaRoles;

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

/**
* retrieve records by their id
* @param vocabularyIds
* @return
* retrieve records by their id, from the in-memory collection
* @param vocabularyIds ids to search for
* @return list of Vocabularies
*/
public List<Vocabulary> findByUri(List<String> vocabularyIds) {
return getEuropeanaRoles().stream()
.filter(el -> vocabularyIds.contains(el.getId()))
.toList();
}

/**
* retrieve records by their id
* @param vocabularyIds ids to search for
* @return list of Vocabularies
*/
public List<Vocabulary> findInDbByUri(List<String> vocabularyIds) {
List<Filter> filters = new ArrayList<>();
filters.add(in(ID, vocabularyIds));
return datastore.find(Vocabulary.class)
Expand Down Expand Up @@ -65,4 +91,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 @@ -86,7 +86,7 @@ public void ensureDatabaseInitialization() throws ApplicationInitializationExcep
roles.add(vocab);
}
vocabRepository.saveBulk(roles);
}
}
}

@Bean(name = BEAN_EM_DATA_SOURCES)
Expand Down

0 comments on commit 7ae0775

Please sign in to comment.