diff --git a/CHANGELOG.md b/CHANGELOG.md index 838fe4387c0..ccdb936299d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Fixed +- We fixed a performance regression when opening large libraries [#9041](https://github.com/JabRef/jabref/issues/9041) + ### Removed diff --git a/src/main/java/org/jabref/model/database/BibDatabase.java b/src/main/java/org/jabref/model/database/BibDatabase.java index 52e4e841ce9..72a559ff663 100644 --- a/src/main/java/org/jabref/model/database/BibDatabase.java +++ b/src/main/java/org/jabref/model/database/BibDatabase.java @@ -20,7 +20,6 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.collections.ObservableSet; import org.jabref.logic.bibtex.FieldWriter; import org.jabref.model.database.event.EntriesAddedEvent; @@ -30,7 +29,6 @@ import org.jabref.model.entry.Month; import org.jabref.model.entry.event.EntriesEventSource; import org.jabref.model.entry.event.EntryChangedEvent; -import org.jabref.model.entry.event.FieldAddedOrRemovedEvent; import org.jabref.model.entry.event.FieldChangedEvent; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; @@ -54,8 +52,6 @@ public class BibDatabase { * State attributes */ private final ObservableList entries = FXCollections.synchronizedObservableList(FXCollections.observableArrayList(BibEntry::getObservables)); - - private final ObservableSet visibleFields = FXCollections.observableSet(); private Map bibtexStrings = new ConcurrentHashMap<>(); private final EventBus eventBus = new EventBus(); @@ -140,8 +136,13 @@ public ObservableList getEntries() { * * @return set of fieldnames, that are visible */ - public ObservableSet getAllVisibleFields() { - return visibleFields; + public Set getAllVisibleFields() { + Set allFields = new TreeSet<>(Comparator.comparing(Field::getName)); + for (BibEntry e : getEntries()) { + allFields.addAll(e.getFields()); + } + return allFields.stream().filter(field -> !FieldFactory.isInternalField(field)) + .collect(Collectors.toSet()); } /** @@ -213,8 +214,6 @@ public synchronized void insertEntries(List newEntries, EntriesEventSo eventBus.post(new EntriesAddedEvent(newEntries, newEntries.get(0), eventSource)); } entries.addAll(newEntries); - - updateVisibleFields(); } public synchronized void removeEntry(BibEntry bibEntry) { @@ -252,7 +251,6 @@ public synchronized void removeEntries(List toBeDeleted, EntriesEventS boolean anyRemoved = entries.removeIf(entry -> ids.contains(entry.getId())); if (anyRemoved) { eventBus.post(new EntriesRemovedEvent(toBeDeleted, eventSource)); - updateVisibleFields(); } } @@ -586,30 +584,6 @@ private void relayEntryChangeEvent(FieldChangedEvent event) { eventBus.post(event); } - @Subscribe - private void listen(FieldAddedOrRemovedEvent event) { - // When a field is removed from an entry we can't tell if it's - // still present in other entries, and thus we can't remove it - // from the set of visible fields. However, when a new field is added - // to any entry, we can simply add it to the set because we're - // going to add it whether other entries have it or not - boolean isAdded = visibleFields.add(event.getField()); - if (!isAdded) { - updateVisibleFields(); - } - } - - private void updateVisibleFields() { - visibleFields.clear(); - Set allFields = new TreeSet<>(Comparator.comparing(Field::getName)); - for (BibEntry e : getEntries()) { - allFields.addAll(e.getFields()); - } - visibleFields.addAll(allFields.stream().filter(field -> !FieldFactory.isInternalField(field)) - .filter(field -> StringUtil.isNotBlank(field.getName())) - .collect(Collectors.toSet())); - } - public Optional getReferencedEntry(BibEntry entry) { return entry.getField(StandardField.CROSSREF).flatMap(this::getEntryByCitationKey); }