Skip to content

Commit

Permalink
Altered JenaQuerierDB.sync() so assets are always written first, so d…
Browse files Browse the repository at this point in the history
…irectly encoded links are not overwritten. Addresses #44.
  • Loading branch information
mike1813 committed Jul 3, 2023
1 parent a44e24d commit d0ec493
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2299,9 +2299,6 @@ public void sync(String... models) {
// First, prepare the cache for synchronisation, removing deletions that were later stored
cache.prepareSync();

// Disable the cache while we synchronise
cacheEnabled = false;

try{
// Start a transaction
dataset.begin(ReadWrite.WRITE);
Expand Down Expand Up @@ -2348,10 +2345,26 @@ public void sync(String... models) {
// Get entities to be stored/updated
Map<String, Map<String, EntityDB>> storeEntitiesByType = cache.getStoreCache(graph);

// Important to store assets first
String assetTypeKey = getCacheTypeName(AssetDB.class);
Map<String, EntityDB> entities = storeEntitiesByType.get(assetTypeKey);
if(entities != null){
if(entities != null && entities.size() > 0){
logger.info("Saving {} new/modified entities cached as {} to graph {}", entities.size(), assetTypeKey, graph);
}
for(EntityDB entity : entities.values()){
persistEntity(entity, graph);
}
}

// Store/update the entities
for(String typeKey : storeEntitiesByType.keySet()){
if(typeKey.equals(getCacheTypeName(AssetDB.class))) {
// Skip the assets, because they were already saved
continue;
}
boolean savingLinks = typeKey.equals(getCacheTypeName(CardinalityConstraintDB.class));
Map<String, EntityDB> entities = storeEntitiesByType.get(typeKey);
entities = storeEntitiesByType.get(typeKey);
if(entities != null){
if(entities != null && entities.size() > 0){
logger.info("Saving {} new/modified entities cached as {} to graph {}", entities.size(), typeKey, graph);
Expand Down Expand Up @@ -2385,9 +2398,6 @@ public void sync(String... models) {
cache.clear();
checkedOutEntityGraphs.clear();

// Re-enable the cache
cacheEnabled = false;

final long endTime = System.currentTimeMillis();
logger.info("JenaQuerierDB.sync(): execution time {} ms", endTime - startTime);

Expand Down

0 comments on commit d0ec493

Please sign in to comment.