Skip to content

Align file-download scheduling with TDLib and fix forum topic loading#344

Open
tdrkDev wants to merge 2 commits into
monogram-android:developfrom
tdrkDev:fix/download-priority-and-topic-load
Open

Align file-download scheduling with TDLib and fix forum topic loading#344
tdrkDev wants to merge 2 commits into
monogram-android:developfrom
tdrkDev:fix/download-priority-and-topic-load

Conversation

@tdrkDev

@tdrkDev tdrkDev commented Jul 21, 2026

Copy link
Copy Markdown

Claude pls fix long loading of chats and media 😭🙏

tdrkDev and others added 2 commits July 21, 2026 14:28
Foreground media (opening an image full screen, a story, a just-opened
chat) loaded slowly because the app-level FileDownloadQueue withheld
requests from TDLib and ordered them opposite to how TDLib schedules.

TDLib has no concurrent-download cap and, among equal priorities, serves
the most recently requested file first (LIFO, per td_api.tl). The queue
capped DEFAULT downloads at 4, sorted equal priorities FIFO, and inferred
"user intent" from priority >= 32 -- which viewport auto-download also
passed, so every scrolled-past thumbnail was marked manual and became
un-evictable, silting up the slots.

Changes:
- Make user intent explicit (userInitiated) instead of inferring it from
  priority; thread it from the tap gesture down to the queue.
- De-saturate calculatePriority so 32 is reserved for real user actions.
- Invert the equal-priority tie-break to LIFO to match TDLib.
- Raise the concurrency caps and remove the 160ms inter-start gap; TDLib
  paces part issuance itself.
- Bypass the queue for user-initiated requests so they reach TDLib at once.
- Re-issue DownloadFile on user action (free bump-to-front in TDLib).
- Cancel stale in-flight downloads (scan activeRequests), not just pending.
- Fix an indefinite story hang: bound the synchronous wait with a timeout
  and never silently drop a synchronous request.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tapping a topic while the forum root was still loading (~2s) silently
dropped the load and left the screen permanently blank with nothing to
retry it.

handleTopicClick() clears `messages` and sets viewportPhase=Initializing,
then calls loadMessages(force = true). But loadMessages returned early on
`if (state.isLoading) return` -- checked before `force` was honoured -- so
the forced load did nothing. With 0 messages and 0 topics the viewport
never settles, so the content animates to alpha 0: no spinner, no error,
no retry.

- Honour force: `if (state.isLoading && !force) return`. cancelAllLoadingJobs()
  already tears down the in-flight load, so pre-empting is safe.
- Guard the finally block with isActive so a pre-empted job (cancelled
  without join) can't clear isLoading after the replacement load set it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant