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

Replace deprecated functions #831

Merged
merged 3 commits into from
Jun 16, 2022
Merged

Replace deprecated functions #831

merged 3 commits into from
Jun 16, 2022

Conversation

juuz0
Copy link
Collaborator

@juuz0 juuz0 commented Apr 12, 2022

This replaces the deprecated Reader and Favicon functions from libkiwix

kiwix::Reader functions are converted to use zim::Archive
Favicon functions are converted to use Illustration
Fixes #805

@juuz0
Copy link
Collaborator Author

juuz0 commented Apr 12, 2022

Removing the reader in suggestionlistworker.cpp should be the last thing to do, to complete this PR. But I'm stuck on how to get suggestions with an archive (wouldn't exposing getSuggestions() from libkiwix internalServer just make it easier? Points to kiwix/libkiwix#740) so would appreciate help on that.

@kelson42 kelson42 requested review from veloman-yunkan and removed request for veloman-yunkan April 12, 2022 13:28
@juuz0
Copy link
Collaborator Author

juuz0 commented Apr 12, 2022

(There's a crash I just found, fixing that..)

Edit: Done ✔️

@juuz0 juuz0 force-pushed the removeLibkiwixDeprecations branch from d0d2e38 to 590a649 Compare April 12, 2022 16:18
@mgautierfr
Copy link
Member

Removing the reader in suggestionlistworker.cpp should be the last thing to do, to complete this PR. But I'm stuck on how to get suggestions with an archive (wouldn't exposing getSuggestions() from libkiwix internalServer just make it easier? Points to kiwix/libkiwix#740) so would appreciate help on that.

As say the small comment in https://github.com/kiwix/libkiwix/blob/master/src/server/internalServer.cpp#L408-L440, searching in the title list using "normalized" case should be done in libzim.
But it is not a easy task (this is also why we introduced xapian tittle index)

I'm partisan to only use SuggestionSearcher in kiwix-desktop. It already fallback to title search (but without case normalization).
For old zim file (before 2019-08) it would be a regression as we would not do case normalization title search (and so suggestion may be less accurate).
If this is really a issue, we should do it where it must be done, in libzim (but I'm not sure it worth the work)

src/library.cpp Outdated Show resolved Hide resolved
src/library.cpp Outdated Show resolved Hide resolved
@juuz0 juuz0 force-pushed the removeLibkiwixDeprecations branch from 590a649 to fc3f093 Compare April 13, 2022 18:27
@juuz0 juuz0 marked this pull request as ready for review April 13, 2022 18:30
@juuz0 juuz0 changed the title [WIP] Replace deprecated functions Replace deprecated functions Apr 13, 2022
@juuz0
Copy link
Collaborator Author

juuz0 commented Apr 13, 2022

For old zim file (before 2019-08) it would be a regression as we would not do case normalization title search (and so suggestion may be less accurate).

For a zim like https://sourceforge.net/projects/telugu-dictionary-zim-file/files/ (from 2016), this will lead to no suggestions, won't that be a major regression for old files?

@stale
Copy link

stale bot commented Apr 28, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

@stale stale bot added the stale label Apr 28, 2022
@juuz0 juuz0 removed the stale label May 7, 2022
@juuz0 juuz0 force-pushed the removeLibkiwixDeprecations branch from fc3f093 to a3b19e2 Compare May 7, 2022 05:11
@juuz0 juuz0 requested a review from mgautierfr May 7, 2022 05:11
@kelson42
Copy link
Collaborator

kelson42 commented May 7, 2022

From a user perspective it looks good. I don't see DEPRECATED warnings during the compilation too. @mgautierfr Please have a look to the code.

src/contentmanager.cpp Show resolved Hide resolved
std::string mimeType;
reader->getFavicon(content, mimeType);
}
auto illustration = archive->getIllustrationItem(48);
Copy link
Member

Choose a reason for hiding this comment

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

We have to handle the case the archive as no 48x48 illustration (pretty rare but anyway)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How do you handle it?
Currently, I have just left the catch block empty.

Copy link
Member

Choose a reason for hiding this comment

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

It depends of the use case.
We probably want to display nothing (in the library or in the tab icon) if the zim has no illustration. It seems that lefting the catch block empty is enough.
(In the library we display a "broken" image. It would be better to not display an image at all. But it is not the purpose of this PR)

src/suggestionlistworker.cpp Outdated Show resolved Hide resolved
src/suggestionlistworker.cpp Show resolved Hide resolved
Comment on lines 32 to 44
zim::Entry getFinalEntry(zim::Entry entry)
{
int loopCounter = 42;
auto final_entry = entry;
while (final_entry.isRedirect() && loopCounter--) {
final_entry = final_entry.getRedirectEntry();
}
// Prevent infinite loops.
if (final_entry.isRedirect()) {
throw zim::EntryNotFound("bad entry");
}
return final_entry;
}
Copy link
Member

Choose a reason for hiding this comment

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

zim::Entry::getItem(true) follows the redirection (until we have a item) and then return the associated item. We could use it directly instead this intermediate function.

Copy link
Member

Choose a reason for hiding this comment

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

Is getFinalEntry still needed as you now use getItem(true) ?

src/webview.cpp Outdated
return;
}
std::string favicon, _mimetype;
reader->getFavicon(favicon, _mimetype);
auto item = archive->getIllustrationItem(48);
Copy link
Member

Choose a reason for hiding this comment

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

We must handle case where archive has not 48x48 illustration

@juuz0 juuz0 force-pushed the removeLibkiwixDeprecations branch 2 times, most recently from 68e38af to afd23e1 Compare May 17, 2022 06:48
@juuz0 juuz0 requested a review from mgautierfr May 17, 2022 06:48
src/library.cpp Outdated
Comment on lines 68 to 75
std::shared_ptr<zim::Searcher> searcher;
auto archive = getArchive(zimId);
if (!searcher) {
searcher = std::make_shared<zim::Searcher>(*archive);
} else {
searcher->addArchive(*archive);
}
return searcher;
Copy link
Member

Choose a reason for hiding this comment

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

This structure (if searcher, add archive else create reader) is usefull only when we loop on a set of archives.
But here we have only one archive

Suggested change
std::shared_ptr<zim::Searcher> searcher;
auto archive = getArchive(zimId);
if (!searcher) {
searcher = std::make_shared<zim::Searcher>(*archive);
} else {
searcher->addArchive(*archive);
}
return searcher;
auto archive = getArchive(zimId);
return std::make_shared<zim::Searcher>(*archive);

Comment on lines 73 to 74
BlobBuffer* buffer = new BlobBuffer(entry.getItem().getData(0));
auto mimeType = QByteArray::fromStdString(entry.getItem(true).getMimetype());
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, it would be better to have either getItem() or getItem(true). But not both.

Comment on lines 32 to 44
zim::Entry getFinalEntry(zim::Entry entry)
{
int loopCounter = 42;
auto final_entry = entry;
while (final_entry.isRedirect() && loopCounter--) {
final_entry = final_entry.getRedirectEntry();
}
// Prevent infinite loops.
if (final_entry.isRedirect()) {
throw zim::EntryNotFound("bad entry");
}
return final_entry;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is getFinalEntry still needed as you now use getItem(true) ?

src/contentmanager.cpp Show resolved Hide resolved
std::string mimeType;
reader->getFavicon(content, mimeType);
}
auto illustration = archive->getIllustrationItem(48);
Copy link
Member

Choose a reason for hiding this comment

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

It depends of the use case.
We probably want to display nothing (in the library or in the tab icon) if the zim has no illustration. It seems that lefting the catch block empty is enough.
(In the library we display a "broken" image. It would be better to not display an image at all. But it is not the purpose of this PR)

if (key == "favicon") {
auto s = b->getFavicon();
auto s = b->getIllustration(48)->getData();
Copy link
Member

Choose a reason for hiding this comment

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

There is not try around this getIllustration

int suggestionsCount = 15;
auto prefix = m_text.toStdString();
auto suggestionSearcher = zim::SuggestionSearcher(*archive);
if (archive->hasTitleIndex()) {
Copy link
Member

Choose a reason for hiding this comment

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

Why limiting suggestion to when archive has a title index ?
If archive has no title index, suggestion may indeed not be the best (as we search in the title listing) but it is better than nothing.

auto suggestionSearch = suggestionSearcher.suggest(prefix);
const auto suggestions = suggestionSearch.getResults(0, suggestionsCount);
for (auto current : suggestions) {
kiwix::SuggestionItem suggestion(current.getTitle(), lcAll(current.getTitle()),
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to use a kiwix::SuggestionItem ?
Could we feed suggestionList, url and urlList directly from current ?

@kelson42
Copy link
Collaborator

@juuz0 Any update?

@stale
Copy link

stale bot commented Jun 12, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

@stale stale bot added the stale label Jun 12, 2022
@mgautierfr mgautierfr force-pushed the removeLibkiwixDeprecations branch from afd23e1 to 6cf07d4 Compare June 16, 2022 08:35
@mgautierfr
Copy link
Member

@juuz0 I've added few fixup commit which should fix my remarks.
Please have a look to them before we merge this branch in master.

@stale stale bot removed the stale label Jun 16, 2022
src/suggestionlistworker.cpp Outdated Show resolved Hide resolved
@juuz0
Copy link
Collaborator Author

juuz0 commented Jun 16, 2022

@mgautierfr LGTM and works too. Only thing remaining is my comment above

juuz0 added 2 commits June 16, 2022 14:25
This replaces the deprecated Reader and Favicon functions from libkiwix

kiwix::Reader functions are converted to use zim::Archive
Favicon functions are converted to use Illustration
Fix #805
Commented out unused variable names in function parameters
Casted unused variable (void) in for-loop
Fixed a signed-unsigned comparison warning
@mgautierfr mgautierfr force-pushed the removeLibkiwixDeprecations branch from 6cf07d4 to b49ea7c Compare June 16, 2022 12:25
@mgautierfr
Copy link
Member

Last comment fixed. Rebase-fixup done.

@mgautierfr mgautierfr merged commit c3eace1 into master Jun 16, 2022
@mgautierfr mgautierfr deleted the removeLibkiwixDeprecations branch June 16, 2022 14:04
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.

Stop using deprecated libkiwix methods
3 participants