-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
It appears the failing |
Made the requested changes, and fixed the |
There was a problem hiding this 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);? |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 BibEntry
s, and you can't have the same entry objects in the same database, so you have to clone them.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
On the |
Would it still be worth my manually testing everything before we merge? |
Sounds plausible!
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. |
I tested the most important changes, and a few things don't work, but those things also don't work on |
Also, I'm working on the
|
@NorwayMaple The database test runs fine on github actions. If you run it locally you have to ensure at least postgres runnning at localhost. |
Thanks again for your contribution!! |
@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 |
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 |
* 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)
This is a work in progress, and I finally got it to compile. It's not tested, and I still have to turn
EntryAddedEvent
intoEntriesAddedEvent
and refactor the code to let it accept that. I also may have to change the SQL inDBMSProcessor
. See #5659.