Skip to content

Reduce startup chat polling & fix blocking request threads

Flo Lee requested to merge reduce-startup-chat-polling into master

Ok this one started on another attempt to find issues with incomplete chat lists or empty chats.

Turn out that first of all, chats were pulled from tdlib even they were already sent before by an updateChat event. So we gonna filter this out to reduce load on the communication. Then, this MR tried (but failed) to implement lazy-loading of chats when the list was scrolled to the bottom. The code is there, does not work, but I would leave it in to immediately continue working with it.

History

Why I want to merge this: During an investigation lasting a few hours @UniversalSuperBox and me finally could pinpoint the issues:

  • QtConcurrent::run uses the default global thread pool, which seems to be limited to the number of CPUs (devices with more CPUs had a better TELEports experience thus)
  • On startup, TELEPorts wants to register push notifications, but that call changed in tdlib when we upgrade to 1.6 - it no longer was void, but returned a result.
  • Our old code expected a void call, and waited for the "Ok" signal, but this never came, instead a return value was given. The thread created by send never completed, as it seems there is no timeout for that situation.
  • The code tried again to register for push, creating a second hung thread
  • Now the thread pool was left with little room, and any further load on TELEports resulted in hanging operations, and unresponsive actions.

How it was fixed

  • Set the default thread pool to allow 99 threads - not a real "solution" but that makes other operations also work smoother
  • Change the ancestor of QTdRegisterDeviceRequest from TdOkRequest to TdRequest, this allows collecting a return value
  • Hook up pushReceiverId event in QTdClient but don´t handle it really (just need to fetch it)
  • Make chat loading a real Quickflux operation with store and such ;)

Note that those fixes were also basically fixed in 0.9.2 hotfix.

Merge request reports