-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix issue #11189 - Implement a caching solution with local storage for citation relations #11845
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
base: main
Are you sure you want to change the base?
Conversation
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.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
You can check review dog's comments at the tab "Files changed" of your pull request.
9fe8522
to
cbe9e96
Compare
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.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
You can check review dog's comments at the tab "Files changed" of your pull request.
cbe9e96
to
8231340
Compare
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.
Your code currently does not meet JabRef's code guidelines.
We use OpenRewrite to ensure "modern" Java coding practices.
The issues found can be automatically fixed.
Please execute the gradle task rewriteRun
, check the results, commit, and push.
You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite".
8231340
to
33967c2
Compare
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.
Your code currently does not meet JabRef's code guidelines.
We use OpenRewrite to ensure "modern" Java coding practices.
The issues found can be automatically fixed.
Please execute the gradle task rewriteRun
, check the results, commit, and push.
You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite".
33967c2
to
592d4d7
Compare
d94f4d3
to
3155242
Compare
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.
Add code explanations to the PR
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryRelationsCache.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryRelationsRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/citation/repository/LRUBibEntryRelationsCache.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/citation/repository/LRUBibEntryRelationsCache.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/citation/repository/LRUBibEntryRelationsRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/importer/fetcher/CitationFetcher.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/citation/service/SearchCitationsRelationsService.java
Outdated
Show resolved
Hide resolved
Please no force push if not needed. All commits will be squashed when merged |
* Move repository, cache, and fetcher to logic package * Move citations model to model/citations/semanticscholar package
* Introduce service layer * Rename LRU cache implementation * Add tests helpers for repository
* Move logic from repository to service * Refactor repositories * Update tab configuration
3155242
to
18db75e
Compare
Sorry, just re-based main branch locally. |
…lation-tab-logic # Conflicts: # src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
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.
In general looks good. Some minor comments.
Sorry for delay. Please go ahead with everything.
src/main/java/org/jabref/logic/citation/service/SearchCitationsRelationsService.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/citation/service/SearchCitationsRelationsServiceTest.java
Outdated
Show resolved
Hide resolved
Small other comments - IntelliJ proposed to extract a method
in the tests - maybe you can also include that. |
@alexandre-cremieux Please pull before you continue working on it - I merged |
src/main/java/org/jabref/logic/citation/repository/LRUBibEntryRelationsRepository.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/citation/service/SearchCitationsRelationsService.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/citation/service/SearchCitationsRelationsService.java
Outdated
Show resolved
Hide resolved
Thanks for the review and the merge. I will resume the work on this branch and apply the changes. |
@alexandre-cremieux Sorry for the merge conflicts - can you handle them? I was always happy with IntelliJ's "resolve merge conflicts" dialog. Hope, it works in this case, too. |
Hello @koppor . Seems that we have new conflicts to resolve to be able to merge main. But I will do that when the feature will be fully developed. Was quite busy last month, I resumed the work this week. PR comments were addressed. |
Hello @calixtus I remove the LRU caching layer and updated the MVStore related code. The store is now opened when the service is created and closed only when the application is shutdown. I tested locally, of course, and it is working. There should not be much change to do anymore and the code should be close to what is expected. Could you please review ? |
jabgui/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
Show resolved
Hide resolved
/** | ||
* TODO: Make the method return a callable and let the calling method create the background task. | ||
*/ | ||
private BackgroundTask<List<BibEntry>> createBackgroundTask( |
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 method should return a Callable instead of directly creating a BackgroundTask, as indicated by the TODO comment, to improve flexibility and separation of concerns.
...main/java/org/jabref/logic/citation/repository/BibEntryCitationsAndReferencesRepository.java
Show resolved
Hide resolved
...main/java/org/jabref/logic/citation/repository/BibEntryCitationsAndReferencesRepository.java
Show resolved
Hide resolved
...java/org/jabref/logic/citation/repository/BibEntryCitationsAndReferencesRepositoryShell.java
Show resolved
Hide resolved
...java/org/jabref/logic/citation/repository/BibEntryCitationsAndReferencesRepositoryShell.java
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/citation/repository/BibEntryRelationRepository.java
Show resolved
Hide resolved
@@ -159,4 +164,16 @@ public ObjectProperty<PlainCitationParserChoice> defaultPlainCitationParserPrope | |||
public void setDefaultPlainCitationParser(PlainCitationParserChoice defaultPlainCitationParser) { | |||
this.defaultPlainCitationParser.set(defaultPlainCitationParser); | |||
} | |||
|
|||
public int getCitationsRelationsStoreTTL() { |
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 method should return an Optional instead of a primitive int to avoid returning null and to align with modern Java practices.
@@ -14,14 +14,14 @@ | |||
|
|||
import com.google.gson.Gson; | |||
|
|||
public class SemanticScholarFetcher implements CitationFetcher, CustomizableKeyFetcher { | |||
public class SemanticScholarCitationFetcher implements CitationFetcher, CustomizableKeyFetcher { |
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 class name was changed from SemanticScholarFetcher to SemanticScholarCitationFetcher, which is a reformatting change without adding new statements. This violates the guideline against reformatting code without adding new statements.
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 just skimmed through the code, just some formatting suggestions.
Others would be doing a thorough review.
JabRefGUI.citationsAndRelationsSearchService = new SearchCitationsRelationsService( | ||
preferences.getImporterPreferences() | ||
); |
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.
Nitpick: one line enough for this
importCitingButton, | ||
citingProgress, | ||
true)); | ||
refreshCitingButton.setOnMouseClicked(event -> { |
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.
refreshCitingButton.setOnMouseClicked(event -> { | |
refreshCitingButton.setOnMouseClicked(_ -> { |
refreshCitingButton.setOnMouseClicked(event -> { | ||
searchForRelations(entry, citingListView, abortCitingButton, | ||
refreshCitingButton, CitationFetcher.SearchType.CITES, importCitingButton, citingProgress); | ||
}); | ||
|
||
refreshCitedByButton.setOnMouseClicked(event -> searchForRelations(entry, citedByListView, abortCitedButton, |
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.
refreshCitedByButton.setOnMouseClicked(event -> searchForRelations(entry, citedByListView, abortCitedButton, | |
refreshCitedByButton.setOnMouseClicked(_ -> searchForRelations(entry, citedByListView, abortCitedButton, |
@@ -82,6 +84,25 @@ public void initialize() { | |||
defaultPlainCitationParser.itemsProperty().bind(viewModel.plainCitationParsers()); | |||
defaultPlainCitationParser.valueProperty().bindBidirectional(viewModel.defaultPlainCitationParserProperty()); | |||
|
|||
viewModel.citationsRelationsStoreTTLProperty() | |||
.addListener((observable, oldValue, newValue) -> { |
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.
.addListener((observable, oldValue, newValue) -> { | |
.addListener((_, _, newValue) -> { |
}); | ||
citationsRelationStoreTTL | ||
.textProperty() | ||
.addListener((observable, oldValue, newValue) -> { |
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.
.addListener((observable, oldValue, newValue) -> { | |
.addListener((_, _, newValue) -> { |
|| !this.relationsRepository.containsReferences(referencer); | ||
if (isFetchingAllowed) { | ||
try { | ||
var references = this.citationFetcher.searchCiting(referencer); |
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.
We usually prefer usage of strict types, but since I see 89 occurrences of it in this PR, I think it is better to let it stay and give energy to other important comments left by the senior developers (if any).
I anyway plan to refactor these throughout the codebase in future.
Thank you @subhramit . Will take your review in account. However, as you mentioned it, please excuse me if I wait for others to review before making the changes. That way I will solve everything in one pass. |
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 serialization and deserialization of BibEntries won't work in all cases. The chosen "canonical representation" is not full BibTeX and there is risk, it cannot be parsed to BibEntry back.
I think, a similar method as org.jabref.gui.ClipBoardManager#serializeEntries
and org.jabref.logic.importer.fileformat.BibtexParser#singleFromString
.
this.store.close(); | ||
} | ||
|
||
static class BibEntrySerializer extends BasicDataType<BibEntry> { |
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, this class is wrong - one should use code similar as org.jabref.gui.ClipBoardManager#serializeEntries
Reason: The result is close to BibTeX, but not a valid BibTeX representation in all cases
- see documentation of the used org.jabref.model.entry.CanonicalBibEntry#getCanonicalRepresentation
…00-refactor-citation-relation-tab-logic
Your pull request needs to link an issue correctly. To ease organizational workflows, please link this pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue:
Examples
|
JUnit tests of You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide. |
@@ -407,6 +415,8 @@ public void stop() { | |||
stopBackgroundTasks(); | |||
LOGGER.trace("Shutting down thread pools"); | |||
shutdownThreadPools(); | |||
LOGGER.trace("Closing citations and relations search service"); | |||
citationsAndRelationsSearchService.close(); |
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 method 'close()' should not be used for normal control flow. Consider using a more descriptive method name that indicates the specific action being performed.
@@ -66,6 +67,8 @@ public class JabRefGUI extends Application { | |||
|
|||
// AI Service handles chat messages etc. Therefore, it is tightly coupled to the GUI. | |||
private static AiService aiService; | |||
// CitationsAndRelationsSearchService is here configured for a local machine and so to the GUI. |
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 comment is trivial and does not add new information beyond what the code already conveys. Comments should provide additional context or reasoning.
I think, this could be overwritten by crowdin - see https://docs.jabref.org/contributing/how-to-translate-the-ui I removed the translations for now - maybe, we can bring them back after a merge. |
citationsRelationStoreTTL.setText(newValue.replaceAll("\\D", "")); | ||
return; | ||
} | ||
viewModel.citationsRelationsStoreTTLProperty().set(Integer.parseInt(newValue)); |
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.
Directly parsing the newValue without validation can lead to NumberFormatException. Ensure the input is validated before parsing to prevent runtime errors.
High level description
This contributions aims to provide a local storage solution for citations relations using MVStore. Please see #11189 for more information.
Fixes #11189
Implementation details
No new dependency added.
Caching strategy
The caching logic of the citations/references is now fully handled by h2.mvstore.MVStore. The store is responsible of the in memory caching and the offline storage logic.
This aims to avoid JabRef to access the Internet if the user already searched for citations/references related to one of its bib entry.
The cache/local store is common to all the libraries managed by the JabRef instance.
Search caching high level logic
Serialization
MVStoreDAO uses the canonical representation to serialize a BibEntry and the
BibtexParser
to deserialize it.Configuration
Citations Relations
tab using the JabRef IoC providercitations
folder under JabRef's app directorySetting translation
The the local storage TTL setting message has been traduced in:
Refactoring
This contributions simplifies the citations/references fetching and caching logic by introducing two layers:
This should help to make this feature more extendable without modifying orchestration logic following open/close principle.
Screen shots
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)