Merge pull request #446 from kiwix/libzim_random

Use the new libzim's getRandomEntry instead of implementing it ourselves.
This commit is contained in:
Matthieu Gautier 2021-03-03 16:04:00 +01:00 committed by GitHub
commit 89d7e68a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 16 deletions

View File

@ -169,23 +169,11 @@ string Reader::getId() const
Entry Reader::getRandomPage() const
{
auto mainPagePath = zimArchive->getMainEntry().getPath();
int watchdog = 42;
while (--watchdog){
auto idx = (zim::size_type)((double)rand() / ((double)RAND_MAX + 1)
* zimArchive->getEntryCount());
auto entry = zimArchive->getEntryByPath(idx);
if (entry.getPath()==mainPagePath) {
continue;
}
auto item = entry.getItem(true);
if (item.getMimetype() == "text/html") {
return entry;
}
try {
return zimArchive->getRandomEntry();
} catch(...) {
throw NoEntry();
}
throw NoEntry();
}
Entry Reader::getMainPage() const