-
Notifications
You must be signed in to change notification settings - Fork 6
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
Check for Duplicates In Mining Mode #109
Conversation
Interesting. Is AnkiConnect responding to, say, 100 separate |
JL.Windows/GUI/PopupWindow.xaml.cs
Outdated
|
||
if (!configManager.MineToFileInsteadOfAnki) | ||
{ | ||
if (MiningUtils.CheckDuplicate(result).Result) |
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.
Accessing the Result
property of a Task
is a blocking operation, thus it should be avoided. Instead we should do something like
bool duplicateCard = await MiningUtils.CheckDuplicate(result).ConfigureAwait(true);
if (duplicateCard)
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.
This is the biggest thing that I'm having trouble with since this method is synchronous.
Toying with something to do the check for duplicates after the window is loaded and toggling the visibility so there is 0 impact on loading the window.
JL.Core/Mining/MiningUtils.cs
Outdated
} | ||
|
||
Dictionary<string, JLField> userFields = ankiConfig.Fields; | ||
Dictionary<JLField, string> miningParams = new() |
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 probably should use GetMiningParameters
here. The implementation provided here just partially creates mining parameters but for all we know the user might have SourceText
as their note type's first field (which is all Anki cares for when checking if a card is a duplicate AFAIK) and its value is missing here.
Or better yet, we can check what's the first Field
in the config and just create a note with that field to check whether it's a duplicate note.
JL.Core/Mining/MiningUtils.cs
Outdated
// Audio/Picture/Video shouldn't be set here | ||
// Otherwise AnkiConnect will place them under the "collection.media" folder even when it's a duplicate note | ||
Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields, ankiConfig.Tags, null, null, null, null); | ||
if (!coreConfigManager.AllowDuplicateCards) |
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.
Why do we have this check here? As is, this method will always return false if the user enabled the Allow duplicate cards
option, is this really the intended behavior?
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.
Already removed in local.
IN 0d51e21
2 things..
|
That being the case, I suggest discarding public Task DisplayResults(bool generateAllResults)
{
...
bool[]? isDuplicateCardArray = null;
int resultCount;
if (generateAllResults)
{
resultCount = LastLookupResults.Count;
CoreConfigManager coreConfigManager = CoreConfigManager.Instance;
if (coreConfigManager.CheckForDuplicateCards
&& !ConfigManager.Instance.MineToFileInsteadOfAnki
&& coreConfigManager.AnkiIntegration)
{
isDuplicateCardArray = await MiningUtils.CheckDuplicates(LastLookupResults, _currentText, _currentCharPosition).ConfigureAwait(true);
}
}
else
{
resultCount = Math.Min(LastLookupResults.Count, ConfigManager.Instance.MaxNumResultsNotInMiningMode);
}
StackPanel[] popupItemSource = new StackPanel[resultCount];
for (int i = 0; i < resultCount; i++)
{
LookupResult lookupResult = LastLookupResults[i];
if (!_dictsWithResults.Contains(lookupResult.Dict))
{
_dictsWithResults.Add(lookupResult.Dict);
}
popupItemSource[i] = PrepareResultStackPanel(lookupResult, i, resultCount, pitchDict, pitchDictIsActive, showPOrthographyInfo, showROrthographyInfo, showAOrthographyInfo, pOrthographyInfoFontSize, isDuplicateCardArray?[i] ?? false);
}
PopupListView.ItemsSource = popupItemSource;
GenerateDictTypeButtons();
UpdateLayout();
} Then we can simply do the following in if (duplicateCard)
{
Button duplicate = new()
{
...
};
_ = top.Children.Add(audioButton);
} I think this is the proper way of doing it. Though I'd like to have some tests regarding the performance impact of doing it like this. |
Yeah, This is how I had it written at some point... But it was the most noticeable in terms of performance for the time I had it in. I'm not really sure I get the technical reason for everything to be final before |
If you used |
Everything done including suggested changes, sitting on it for a bit to test and refactor. |
Moved Icon to the end of the row so we can actually toggle visibility of the icon instead of uncollapse it PR review changes like return types, array instead of List, etc. Changed to Textblock instead of button Made method to get first mining param instead of getting everything and then only getting the first.
Sorry for the delay on this. in a687c8d.
Edit: Realized I forgot to include an image of what it looks like on the end. |
Fill out GetMiningParameter Method Move duplicateIcons List out of Fields More small Object/List Related Changes
Changes in dbcc60a all per PR. Bulk of this commit is in
|
Add braces to case refactor frequencies to inline conditional get rid of unused var in Preferred Frequency move unused and default cases to top moved ankiconfigcheck downmerged from upstream changed to array instead of list per upstream change other small pr related changes
Co-authored-by: rampaa <[email protected]>
In a5aee43, more changes per PR review Add braces to case |
Thanks for contributing to JL! |
closes #107.
Added a config (default false) for checking duplicates when entering mining mode.
This will check all the results in mining mode for an already existing expression in the configured anki deck, and display a warning next to the result if it finds one.
Creating this as a draft as I want to: