-
-
Notifications
You must be signed in to change notification settings - Fork 447
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
Use libkiwix to store bookmarks #3653
Conversation
533e081
to
db6601d
Compare
b32db28
to
1b2e5dd
Compare
@MohitMaliFtechiz What is the status here? I don‘t understand why such a simple thing like handling bookamrks takes so mich time?! |
@kelson42 Migrating bookmarks is working correctly now with low-end devices as well(at least for 10K bookmarks), I was improving the large data migration in lower devices so that it will migrate the bookmarks easily on the lower devices, The main issue is there are some random test failures on CI after these change. But locally all the test cases are passing, so I am finding the actual cause of these failures. |
@MohitMaliFtechiz What do you mean with "large data"? bookmarks are small amount of data, how is that possible that migrating them somehow is a performance problem? |
@kelson42 I mean a large amount of We have improved our migration and data loading process from libkiwix to avoid this kind of error. |
@MohitMaliDeveloper There is not reason that migration 10K bookmarks takes more than a few seconds. And BTW, do you know anybody with 10K bookmarks even in its browser? I have also no clue what you mean with "some local variables (archive, bookmark")?! Please be precise and extrem clear in what you write. |
@kelson42 My explanation was short to understand properly what was going on. In the migrating process, I have tested it with different scenarios to make sure everything will work fine in every scenario. e.g. It will not affect the performance of the application when there many numbers of bookmarks are available in the libkiwix. Since now we do not have any database(so that we can filter the data to show) we are directly saving the bookmarks in a file via libkiwix and we have to retrieve the full bookmarks data from libkiwix and perform the filtration on that data for current books bookmark, so when I was performing this operation with 512 bookmarks on Android 8 it was giving me Local reference table overflow so I was making sure everything works perfectly without any error in every scenario.
I don't know any person who has the 10K bookmarks, but being a developer we should be ready for every scenario.
I mean, during the bookmark migration, we were creating archive/bookmark objects for saving them to the library. However, these objects were not being garbage collected due to being inside a loop. Consequently, these local variables were retained in memory. Similar issues arose when retrieving bookmarks from libkiwix for display. I resolved these errors, and the fixes took only a few hours. The primary challenges, though, were encountered in the test cases. Since we lacked direct access to libkiwix functions in our unit test cases, we needed wrapper classes for access. Unfortunately, there were issues with accessing the |
25d241e
to
9746fc2
Compare
@gouri-panda, @kelson42 This PR is ready for review as now there is nothing left to implement on the Android side only an issue is occurring with libkiwix for that I have opened a ticket on the libkiwix kiwix/java-libkiwix#80. I am keeping this PR in the draft due to the error of libkiwix on Android 24. |
@MohitMaliFtechiz We should review and merge this ticket independently of kiwix/java-libkiwix#80 |
@kelson42 It is working fine with API level 26(Android 8) but I am concerned about lower devices if someone has bookmarks more than 512 it will crash the application. |
I don't think that anybody has more than 500 bookmarks, please put in review if this is the only known problem. |
09bbfae
to
ed4eb35
Compare
@gouri-panda This PR is ready for review. |
@MohitMaliFtechiz Please rebase and fix conflict |
8d714e1
to
0a31d8f
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.
@kelson42 I've reviewed and tested this PR so far it looks good but i think i should review this again for edge cases since this is a big and important PR i may've missed something. Give me another day to review this properly.
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.
@MohitMaliDeveloper Thanks for the robust tests! LGTM!
@MohitMaliFtechiz Can you please rebase (a last time) |
* We introduced a Flowable list in LibkiwixBookmarks to observe live changes on the UI. Previously, the UI was not updating after deleting bookmarks on the BookmarkScreen, and toggling bookmarks in the reader screen was also not reflecting the changes. To address this, we created a Flowable list and are now observing it whenever bookmarks are added or removed in the library.
…save the `library`, which contains information about books, their file paths, and favicons, into a file. * We now save this library information into a file named `library.txt` and subsequently read from it to retrieve file paths and favicons. * The test cases have been refactored to accommodate this new functionality. * The `ObjectBoxToLibkiwiMigrator` code has also been enhanced. With this change, we now save books in the library for their favicon and zimFilePath, resulting in a refactor and improvement of this class's functionality and its associated test cases. * The process of writing bookmarks and library data to file has been enhanced. Now, this is performed asynchronously in a background thread to mitigate potential data loss. * Additionally, several other improvements have been made throughout the codebase.
… since we don't need these classes as saving/deleting functionality will be tested in java-libkiwix. * Added instrumentation test case for testing the UI part with libkiwix bookmark functionality.
…etrieve the saved bookmarks. * Enhanced the `isBookMarkExist` method, addressing a bug that prevented the addition of new bookmarks for the same file. The method has been refactored for improved functionality. * In the debug version, added informative logs to provide developers with insights into the bookmark-saving functionality.
…e current book has been removed because adding the book to the library is unnecessary, as we have not saved any bookmarks yet. * We now write bookmarks and the library on the main thread instead of saving them in the background thread to prevent any data loss.
…d logs before writing the library in file.
…he favicon from it, we are now speeding up the process by directly taking the favicon from the book, as the issue at kiwix/java-libkiwix#73 has been resolved.
* Removed unused imports.
…id impacting application performance.
* Improved the instrumentation test cases. * Improved the migration test case.
* Refined test cases to thoroughly assess the migration process. * Enhanced the migration logic to effectively manage large datasets during migration. * Optimized the Bookmark functionality to minimize unnecessary data loading on libkiwix. Retrieving data from libkiwix is now performed only when there is a change in the bookmark, reducing redundant data fetches. Otherwise, the previously loaded data is returned to minimize unnecessary resource access.
* Enhanced the process of adding books to the library to prevent unnecessary data loading from libkiwix. * Released the memory occupied by bookmarks and archives to resolve potential issues when running migrations on lower-end devices.
* Re-enabled test case for migrating bookmarks more then 512 to test it properly on API level 24.
10eda26
to
8199480
Compare
@kelson42 Done. |
@MohitMaliDeveloper Thx. I have look very briefly to this big PR. Here is what I'm missing:
|
@kelson42 We have the ObjectBoxToLibkiwixMigrator class which handles the migration. Also, I have updated the PR description with the necessary details. Let me know if anything I am missing something. |
Fixes #3109
ObjectBox
. Libkiwix allows us to save bookmarks in a file with the help of the Library, and we can save the library too in a file, the library contains the contains ZIM file paths and favicons in it so we are saving both library/bookmarks in a file. We can read these saved files via the Manager class to retrieve the saved bookmarks/library content.Bookmarks
folder of our app-specific directory.ObjectBox
toLibkiwix
we have created ObjectBoxToLibkiwixMigrator class which handles the migration part. We have not deleted the previous data from theObjectBox
yet to prevent any data loss.