Skip to content

Commit

Permalink
Improve performance with duplicate check on paste (#11843)
Browse files Browse the repository at this point in the history
* Improve performance with duplicate check on paste

* changelog

* refine changelopg
  • Loading branch information
Siedlerchr authored Sep 28, 2024
1 parent bd5439a commit 538f0ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We improved the display of long messages in the integrity check dialog. [#11619](https://github.com/JabRef/jabref/pull/11619)
- We improved the undo/redo buttons in the main toolbar and main menu to be disabled when there is nothing to undo/redo. [#8807](https://github.com/JabRef/jabref/issues/8807)
- We improved the DOI detection in PDF imports. [#11782](https://github.com/JabRef/jabref/pull/11782)
- We improved the performance when pasting and importing entries in an existing library. [#11843](https://github.com/JabRef/jabref/pull/11843)

### Fixed

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,21 @@ public void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext,

private void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext, BibEntry entry, DuplicateResolverDialog.DuplicateResolverResult decision) {
BibEntry entryToInsert = cleanUpEntry(bibDatabaseContext, entry);
Optional<BibEntry> existingDuplicateInLibrary = findDuplicate(bibDatabaseContext, entryToInsert);
if (existingDuplicateInLibrary.isPresent()) {
Optional<BibEntry> duplicateHandledEntry = handleDuplicates(bibDatabaseContext, entryToInsert, existingDuplicateInLibrary.get(), decision);
if (duplicateHandledEntry.isEmpty()) {
return;
}
entryToInsert = duplicateHandledEntry.get();
}
importCleanedEntries(List.of(entryToInsert));
downloadLinkedFiles(entryToInsert);

BackgroundTask.wrap(() -> findDuplicate(bibDatabaseContext, entryToInsert))
.onFailure(e -> LOGGER.error("Error in duplicate search"))
.onSuccess(existingDuplicateInLibrary -> {
BibEntry finalEntry = entryToInsert;
if (existingDuplicateInLibrary.isPresent()) {
Optional<BibEntry> duplicateHandledEntry = handleDuplicates(bibDatabaseContext, entryToInsert, existingDuplicateInLibrary.get(), decision);
if (duplicateHandledEntry.isEmpty()) {
return;
}
finalEntry = duplicateHandledEntry.get();
}
importCleanedEntries(List.of(finalEntry));
downloadLinkedFiles(finalEntry);
}).executeWith(taskExecutor);
}

@VisibleForTesting
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/database/DuplicateCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static double[] compareRequiredFields(final BibEntryType type, final Bib

private static boolean isFarFromThreshold(double value) {
if (value < 0.0) {
LOGGER.debug("Value {} is below zero. Should not happen", value);
LOGGER.trace("Value {} is below zero. Should not happen", value);
}
return value - DuplicateCheck.DUPLICATE_THRESHOLD > DuplicateCheck.DOUBT_RANGE;
}
Expand Down Expand Up @@ -309,7 +309,7 @@ private static double similarity(final String first, final String second) {
}
final double distanceIgnoredCase = new StringSimilarity().editDistanceIgnoreCase(longer, shorter);
final double similarity = (longerLength - distanceIgnoredCase) / longerLength;
LOGGER.debug("Longer string: {} Shorter string: {} Similarity: {}", longer, shorter, similarity);
LOGGER.trace("Longer string: {} Shorter string: {} Similarity: {}", longer, shorter, similarity);
return similarity;
}

Expand Down

0 comments on commit 538f0ee

Please sign in to comment.