Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Batch Insert entries #5691

Merged
merged 86 commits into from
Dec 30, 2019
Merged

[WIP] Batch Insert entries #5691

merged 86 commits into from
Dec 30, 2019

Conversation

abepolk
Copy link
Contributor

@abepolk abepolk commented Dec 2, 2019

This is a work in progress, and I finally got it to compile. It's not tested, and I still have to turn EntryAddedEvent into EntriesAddedEvent and refactor the code to let it accept that. I also may have to change the SQL in DBMSProcessor. See #5659.

@koppor koppor removed their assignment Dec 20, 2019
@abepolk
Copy link
Contributor Author

abepolk commented Dec 23, 2019

It appears the failing databaseTest was simply due to a bug in my ininsertEntries method, which I solved with a one-line fix.

@abepolk
Copy link
Contributor Author

abepolk commented Dec 24, 2019

Made the requested changes, and fixed the databaseTests. Is there anything else to do before I manually test it?

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your Christmas present 🎄. The code looks really good and I have only a few very minor remarks (mostly concerning naming conventions and the like).

It would be nice if you could implement these minor things, and cleanup the code a bit (removing obsolete todo comments for example). Then we can merge.

@@ -161,7 +161,7 @@ public void runFetcherWorker() {
} else {
// Regenerate CiteKey of imported BibEntry
new BibtexKeyGenerator(basePanel.getBibDatabaseContext(), prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry);
basePanel.insertEntry(entry);
basePanel.insertEntry(entry); // Should this be basePanel.getDatabase().insertEntry(entry);?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think basePanel.insertEntry is indeed the better choice, because of the extra work it does. BibDatabase.insertEntry is just the plain insertion of the entry in the database.

@@ -217,17 +216,12 @@ public void paste() {
List<BibEntry> entriesToAdd = Globals.clipboardManager.extractData();

if (!entriesToAdd.isEmpty()) {
// Add new entries
NamedCompound ce = new NamedCompound((entriesToAdd.size() > 1 ? Localization.lang("paste entries") : Localization.lang("paste entry")));
database.getDatabase().insertEntries(entriesToAdd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check if the UpdateField.setAutomaticFields call is then still required or if it's part of basePanel.insertEntries.

public class UndoableInsertEntries extends AbstractUndoableJabRefEdit {

private static final Logger LOGGER = LoggerFactory.getLogger(UndoableInsertEntries.class);
private final BibDatabase base;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename base to database.

BibEntry clonedEntry = (BibEntry) entry.clone();
result.getGeneratedBibDatabase().insertEntry(clonedEntry);
private void insertEntries(List<BibEntry> entries, AuxParserResult result) {
List<BibEntry> clonedEntries = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don´t think the clone is actually necessary, can you please try to remove it. Thanks

* @return BibDatabase that contains the entries
*/
public static BibDatabase createDatabase(Collection<BibEntry> bibentries) {
public static BibDatabase createDatabase(Collection<BibEntry> bibEntries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think entries as a name is already sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why you don't think the clone is necessary. It is my understanding that the AuxParserResult should have a separate database with separate BibEntrys, and you can't have the same entry objects in the same database, so you have to clone them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the clone method is too create a copy with the same data in such a way that you can modify the clone without modifying the original entry. For example for copy/pasting, you do not want to have a literal copy of the same entry as then modification to the pasted entry would transfer to the copied one.

I thought the AuxParser creates a bunch of new entries, and then the clone is not necessary. But you are right the clone might be necessary because the entries are not created but only copied. My bad! Thanks for pointing it out.

BibDatabase database = new BibDatabase();

for (BibEntry entry : bibentries) {
for (BibEntry entry : bibEntries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be mistaken but I think insertEntries already takes care of the id generation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insertEntries add existing IDs to the database, but does not set them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I just noticed that BibDatabases.createDatabase is only called outside of test in ParserResult. Also, all BibEntry constructors assign an ID to each BibEntry. Is it possible that the IDs are being changed for something that relates to parsing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, IDs should be fixed upon creation and are never changed. Moreover, they are only used in the connection with shared databases to identify remote entries with local ones. Thus, I guess this method can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this method is only used in ParserResult (and test). Perhaps we can remove the method entirely. In addition, based on what you said about IDs not changing, it might be worth it to remove the setId method from BibEntry, which is only called in BibDatabases.createDatabase and test. Maybe that could be in another PR. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Do you want to work on this, too? Then I let you decide if you want to implement it as part of this PR or a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it as a new PR once I've finished this one and the DBMS synchronization.

@abepolk
Copy link
Contributor Author

abepolk commented Dec 24, 2019

todo

On the TODO in UndoableInsertEntries, it seems that we don't have to keep track of the entry editors that are open because if we remove them in an undo, an entriesRemovedEvent will be fired, and EntryRemovedListener (which I will rename EntriesRemovedListener) in BasePanel will close the entry editor with the listen() method. This would have to be tested.

@abepolk
Copy link
Contributor Author

abepolk commented Dec 24, 2019

Would it still be worth my manually testing everything before we merge?

@tobiasdiez
Copy link
Member

On the TODO in UndoableInsertEntries, it seems that we don't have to keep track of the entry editors that are open because if we remove them in an undo, an entriesRemovedEvent will be fired, and EntryRemovedListener (which I will rename EntriesRemovedListener) in BasePanel will close the entry editor with the listen() method. This would have to be tested.

Sounds plausible!

Would it still be worth my manually testing everything before we merge?

It would be good if you could test the major changes, or where you are unsure that your changes had indeed the correct effects. Extensive testing is not necessary. To be honest: developer time is precious and we usually rely on our users to report issues that might be introduced due to recent changes. That works (surprisingly?) well for us as we have a lot of active users that try the recent development versions.

@abepolk
Copy link
Contributor Author

abepolk commented Dec 30, 2019

I tested the most important changes, and a few things don't work, but those things also don't work on master. In other words, it doesn't appear that I broke anything that worked before. Should we merge?

@abepolk
Copy link
Contributor Author

abepolk commented Dec 30, 2019

Also, I'm working on the DBMSProcessor (which will be in a separate PR) and am having trouble running databaseTest. For each failed test, I get the same error. See below. Any ideas how to troubleshoot it?

  org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
      at org.jabref.logic.shared.DBMSProcessorTest.setup(DBMSProcessorTest.java:45)
  Caused by: java.net.ConnectException: Connection refused
      at org.jabref.logic.shared.DBMSProcessorTest.setup(DBMSProcessorTest.java:45)

@Siedlerchr
Copy link
Member

@NorwayMaple The database test runs fine on github actions. If you run it locally you have to ensure at least postgres runnning at localhost.

@tobiasdiez tobiasdiez merged commit 371a863 into JabRef:master Dec 30, 2019
@tobiasdiez
Copy link
Member

Thanks again for your contribution!!

@koppor
Copy link
Member

koppor commented Dec 31, 2019

@NorwayMaple What do you mean with "a few things don't work"? Could you open an issue for that so that we can track it?

@NorwayMaple Do you have a local PostgreSQL instance running? The string Connection to localhost:5432 indicates that no local PostgreSQL is running on port 5432 on your local machine.

@abepolk
Copy link
Contributor Author

abepolk commented Dec 31, 2019

I had trouble copying entries from one database into another database. The copy appeared to work, but the paste didn't. I can make an issue later.

I got the PostgreSQL and databaseTest to work.

Siedlerchr added a commit that referenced this pull request Jan 4, 2020
* upstream/master:
  Add select all buttons to change dialog (#5803)
  Squashed 'src/main/resources/csl-locales/' changes from 9785a6e358..a3e8843f75
  Squashed 'src/main/resources/csl-styles/' changes from 49a1841..b2fbe15
  Fix CSL update
  Add new authors
  Remove ACM Fetcher in one more check
  Adapt WebFetchersTest
  Disable ACM Fetcher
  Try to fix branch name on cleanup pr action
  Remove obsolete class (#5801)
  Try to use right ref
  Run tests only once at pull requets
  Add ignored dependency
  Fix "&" on previews (#5786)
  [WIP] Batch Insert entries (#5691)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants