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

Fixed: Improve article search in our application. #3849

Merged
merged 4 commits into from
May 17, 2024
Merged

Fixed: Improve article search in our application. #3849

merged 4 commits into from
May 17, 2024

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented May 16, 2024

Fixes #3848

  • Now we are using the same ZimFileReader object to search the articles. It reduces the search timing and avoids unnecessary allocation of objects in memory.

  • Refactored the SearchViewModelTest for this change.

  • After this change, a few codes are become unused so we have removed that from our application.

  • Fixed the test cases that were failing if testPauseAndResumeInOtherLanguage failed due to any reason. Because the language remains changed and other test cases will fail. Like it was failed in this PR on API level 30(/~https://github.com/kiwix/kiwix-android/actions/runs/9113243814/job/25054265367).

  • Also, improved our DownloadTest, because after changing the language of the application online content will change according to the new language so now we are using a generic approach for downloading the zim file.

  • Fixed the crash that playStore reported. It was due to the render method was called multiple times (7-14 times) when an item in the search list is clicked, which leads to unnecessary data loading and also causes a crash. The issue arises because the searchViewModel takes a moment to detach from the window, and during this time, this method is called multiple times due to the rendering process. To avoid unnecessary data loading and prevent crashes, we check if the search screen is visible to the user before proceeding. If the screen is not visible, we skip the data loading process. Below are crash logs reported by the playStore, and the same crash logs are generated by my device.

Cmdline: org.kiwix.kiwixmobile
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A  pid: 6773, tid: 7126, name: DefaultDispatch  >>> org.kiwix.kiwixmobile <<<
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #00 pc 0000000000230120  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #01 pc 0000000000230cb4  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (std::__ndk1::list<std::__ndk1::pair<unsigned int, std::__ndk1::shared_ptr<zim::Dirent const> >, std::__ndk1::allocator<std::__ndk1::pair<unsigned int, std::__ndk1::shared_ptr<zim::Dirent const> > > >::splice(std::__ndk1::__list_const_iterator<std::__ndk1::pair<unsigned int, std::__ndk1::shared_ptr<zim::Dirent const> >, void*>, std::__ndk1::list<std::__ndk1::pair<unsigned int, std::__ndk1::shared_ptr<zim::Dirent const> >, std::__ndk1::allocator<std::__ndk1::pair<unsigned int, std::__ndk1::shared_ptr<zim::Dirent const> > > >&, std::__ndk1::__list_const_iterator<std::__ndk1::pair<unsigned int, std::__ndk1::shared_ptr<zim::Dirent const> >, void*>)+96)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #02 pc 000000000022f53c  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::lru_cache<unsigned int, std::__ndk1::shared_ptr<zim::Dirent const> >::get(unsigned int const&)+204)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #03 pc 000000000022ee14  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::DirectDirentAccessor::getDirent(zim::entry_index_t) const+92)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #04 pc 0000000000244e1c  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::DirentLookup<zim::FileImpl::DirentLookupConfig>::compareWithDirentAt(char, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, unsigned int) const+80)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #05 pc 0000000000244658  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::DirentLookup<zim::FileImpl::DirentLookupConfig>::findInRange(unsigned int, unsigned int, char, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) const+308)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #06 pc 000000000023c05c  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::FastDirentLookup<zim::FileImpl::DirentLookupConfig>::find(char, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) const+124)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #07 pc 0000000000238ca8  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::FileImpl::findx(char, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)+72)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #08 pc 0000000000238d6c  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::FileImpl::findx(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)+140)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #09 pc 0000000000215ce8  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::Archive::getEntryByPath(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) const+564)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #10 pc 00000000002a65f0  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::SuggestionIterator::SuggestionInternalData::get_entry()+152)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #11 pc 00000000002a5390  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::SuggestionIterator::getIndexTitle() const+84)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #12 pc 00000000002a5688  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim.so (offset 0x1400000) (zim::SuggestionIterator::operator*()+168)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #13 pc 0000000000028548  /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!libzim_wrapper.so (offset 0x626000) (Java_org_kiwix_libzim_SuggestionIterator_next+500) (BuildId: eb23384a06a222c0ee4838412233ff48d1d128df)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #19 pc 00000000000074e4  /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes11.dex (org.kiwix.kiwixmobile.core.search.viewmodel.SearchState.getVisibleResults+0)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #24 pc 0000000000006a78  /data/data/org.kiwix.kiwixmobile/code_cache/.overlay/base.apk/classes10.dex (org.kiwix.kiwixmobile.core.search.SearchFragment$render$2$1$searchResult$1.invokeSuspend+0)
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #34 pc 00000000003562e4  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!classes29.dex]
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #39 pc 000000000036364c  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!classes29.dex]
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #44 pc 0000000000361ccc  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!classes29.dex]
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #49 pc 000000000035fddc  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!classes29.dex]
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #54 pc 000000000035ffd8  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!classes29.dex]
2024-05-17 18:04:28.835  7150-7150  DEBUG                   pid-7150                             A        #59 pc 000000000035ffac  [anon:dalvik-classes29.dex extracted in memory from /data/app/~~gt9Pp7_lZdkwP2e02Egrww==/org.kiwix.kiwixmobile-Js9e1XXFsUslmGj9kqciZA==/base.apk!classes29.dex]
  • Added the test cases for this scenario so that we can avoid this type of errors in future.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft May 16, 2024 13:30
Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.90%. Comparing base (e4924d8) to head (412fdb9).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #3849   +/-   ##
=========================================
  Coverage     53.90%   53.90%           
+ Complexity     1333     1331    -2     
=========================================
  Files           292      292           
  Lines         11119    11113    -6     
  Branches       1480     1477    -3     
=========================================
- Hits           5994     5991    -3     
+ Misses         4147     4138    -9     
- Partials        978      984    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* Now we are using the same `ZimFileReader` object to search the articles. It reduces the search timing and avoids unnecessary allocation of objects in memory.
* Refactored the `SearchViewModelTest` for this change.
* After this change there is some unused code so we have removed that from our application.
…anguage` failed due to any reason. Because the language remains changed and other test cases will fail. Like it was failed in this PR on API level 30.

* Also, improved our `DownloadTest`, because after changing the language of the application online content will change according to the new language so now we are using a generic approach for downloading the zim file.
@kelson42
Copy link
Collaborator

So, badically, no user workflow changes?

@MohitMaliFtechiz
Copy link
Collaborator Author

So, badically, no user workflow changes?

@kelson42 No, no workflow will change. With this change, we have improved the search functionality, now search works faster even in bigger zim files as now we are not creating unnecessary objects of ZimFileReader that take a few moments to create with bigger zim files. Also, it resolved the crashing problem with the search functionality that playStore reported.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review May 17, 2024 13:10
@MohitMaliFtechiz MohitMaliFtechiz requested a review from kelson42 May 17, 2024 13:11
@kelson42 kelson42 merged commit 95ef46a into main May 17, 2024
10 checks passed
@kelson42 kelson42 deleted the Fix#3848 branch May 17, 2024 17:02
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.

Improve article search in our application.
3 participants