Skip to content

Commit

Permalink
Fix performance regresssion (#9045)
Browse files Browse the repository at this point in the history
Revert bibdatabasemode to previous state

Fixes #9041
  • Loading branch information
Siedlerchr authored Aug 11, 2022
1 parent f06e564 commit 60f5c1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
40 changes: 7 additions & 33 deletions src/main/java/org/jabref/model/database/BibDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -54,8 +52,6 @@ public class BibDatabase {
* State attributes
*/
private final ObservableList<BibEntry> entries = FXCollections.synchronizedObservableList(FXCollections.observableArrayList(BibEntry::getObservables));

private final ObservableSet<Field> visibleFields = FXCollections.observableSet();
private Map<String, BibtexString> bibtexStrings = new ConcurrentHashMap<>();

private final EventBus eventBus = new EventBus();
Expand Down Expand Up @@ -140,8 +136,13 @@ public ObservableList<BibEntry> getEntries() {
*
* @return set of fieldnames, that are visible
*/
public ObservableSet<Field> getAllVisibleFields() {
return visibleFields;
public Set<Field> getAllVisibleFields() {
Set<Field> 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());
}

/**
Expand Down Expand Up @@ -213,8 +214,6 @@ public synchronized void insertEntries(List<BibEntry> newEntries, EntriesEventSo
eventBus.post(new EntriesAddedEvent(newEntries, newEntries.get(0), eventSource));
}
entries.addAll(newEntries);

updateVisibleFields();
}

public synchronized void removeEntry(BibEntry bibEntry) {
Expand Down Expand Up @@ -252,7 +251,6 @@ public synchronized void removeEntries(List<BibEntry> toBeDeleted, EntriesEventS
boolean anyRemoved = entries.removeIf(entry -> ids.contains(entry.getId()));
if (anyRemoved) {
eventBus.post(new EntriesRemovedEvent(toBeDeleted, eventSource));
updateVisibleFields();
}
}

Expand Down Expand Up @@ -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<Field> 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<BibEntry> getReferencedEntry(BibEntry entry) {
return entry.getField(StandardField.CROSSREF).flatMap(this::getEntryByCitationKey);
}
Expand Down

0 comments on commit 60f5c1b

Please sign in to comment.