Skip to content

Commit

Permalink
test further
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Sep 2, 2022
1 parent bf51775 commit d0e7237
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ public synchronized void synchronizeLocalDatabase() {
return;
}

List<BibEntry> localEntries = bibDatabase.getEntries();
List<BibEntry> localEntries = new ArrayList<>(bibDatabase.getEntries());
Map<Integer, Integer> idVersionMap = dbmsProcessor.getSharedIDVersionMapping();

List<BibEntry> entriesToUpdates = new ArrayList<>();

// remove old entries locally
removeNotSharedEntries(localEntries, idVersionMap.keySet());
List<Integer> entriesToInsertIntoLocalDatabase = new ArrayList<>();
Expand All @@ -212,14 +214,12 @@ public synchronized void synchronizeLocalDatabase() {
Optional<BibEntry> sharedEntry = dbmsProcessor.getSharedEntry(idVersionEntry.getKey());
if (sharedEntry.isPresent()) {
// update fields

localEntry.setType(sharedEntry.get().getType(), EntriesEventSource.SHARED);
localEntry.getSharedBibEntryData()
.setVersion(sharedEntry.get().getSharedBibEntryData().getVersion());


taskExecutor.runInFXThread(()-> {


sharedEntry.get().getFieldMap().forEach(
// copy remote values to local entry
(field, value) -> localEntry.setField(field, value, EntriesEventSource.SHARED)
Expand All @@ -231,21 +231,23 @@ public synchronized void synchronizeLocalDatabase() {
.forEach(
field -> localEntry.clearField(field, EntriesEventSource.SHARED)
);
});
}
}
entriesToUpdates.add(localEntry);
}

if (!remoteEntryMatchingOneLocalEntryFound) {
entriesToInsertIntoLocalDatabase.add(idVersionEntry.getKey());
}
}

// TODO: Update at once? or wrap whole method again in taskExecutor?


if (!entriesToInsertIntoLocalDatabase.isEmpty()) {

taskExecutor.runInFXThread( () -> bibDatabase.insertEntries(dbmsProcessor.getSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED));
taskExecutor.runInFXThread( () -> bibDatabase.insertEntries(dbmsProcessor.partitionAndGetSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED) );
// in case entries should be added into the local database, insert them
bibDatabase.insertEntries(dbmsProcessor.partitionAndGetSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED);
}
}

Expand Down

0 comments on commit d0e7237

Please sign in to comment.