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

More cleanup of download management related code in ContentManager #1045

Merged
merged 19 commits into from
Mar 7, 2024

Conversation

veloman-yunkan
Copy link
Collaborator

@veloman-yunkan veloman-yunkan commented Feb 27, 2024

This PR is the next batch of changes extracted from #1038 and a follow-up to #1041.

The ugliest design issue that is solved by this PR is the convoluted download update operation:

  1. Download update timer (one per active download, running in the main event loop) fires and invokes
  2. ContentManagerModel::updateDownload() which then calls
  3. DownloadState::update() which calls
  4. ContentManager::updateDownloadInfos() which
  5. may update the download list (when the download is found to be completed or cancelled) and trigger a reinitialization of the ContentManagerModel

Now the entire logic of the download update operation is concentrated in the ContentManager::updateDownload() method in a comprehensible way.

The main user-observable change is that now there is a single timer for download updates - when it fires all active downloads are updated.

Also fixed a bug introduced in the previous PR that resulted in the download progress not working for the first row.

In theory, a book recorded in a local library may have only its url defined
(and no path to a ZIM file). Such a book qualifies as downloadable too.

That's why the call to `ContentManager::getRemoteOrLocalBook()` (which
may return a "local" book) perfectly makes sense in
`ContentManager::downloadBook()`.

However, it doesn't then make sense to raise an error if the returned
book turns out to be a "local" one. It would be more logical to request
only for a remote book and report an error if that operation fails.
Inlined ContentManagerModel::startDownload() into
ContentManager::downloadBook().
Now there is a single timer in ContentManager shared by all pending downloads.
Temporarily, all active downloads are updated on every firing of the
timer and this happens in the main thread. This will be changed later.

The main objective of this change is to get rid of the timer in
DownloadState so that it can be converted to a dumb struct set by
ContentManager.
DownloadState::update() no longer calls ContentManager::updateDownloadInfos()
The commit "Moved download deregistration to ContentManager" introduced
a bug - completed downloads were not properly deregistered.

Note that a simpler fix by adding a single `m_downloads.remove(bookId);`
line in `ContentManager::downloadCompleted()` didn't work (which means
that that function is not always called upon download completion). I am
not going to investigate that issue now, hoping that it will be
automatically resolved once the redesign of download management is
finished.
Now ContentManager::updateDownloadInfos() is called directly by
ContentManager (rather than indirectly via ContentManagerModel).
... by inlining it into ContentManager::updateDownload()
Copy link
Member

@mgautierfr mgautierfr left a comment

Choose a reason for hiding this comment

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

LGTM

@mgautierfr mgautierfr merged commit 75ecdeb into main Mar 7, 2024
4 checks passed
@mgautierfr mgautierfr deleted the refactoring branch March 7, 2024 12:56
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.

2 participants