Improve UpdateManager #55
HedgehogNSK
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
|
Hey @HedgehogNSK 👋 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there. :) I have an idea how to improve the UpdateManager. But I don't have much time to fully accomplish this task. So I share my yet not working draft code here. I suppose you will understand the idea.
The idea is bring more reactivity to UpdateManager.
RIght now
UpdateManager uses Enum for each type of update request and it uses several classes to process and distribute responses. And the core uses strange connection between async method and creates reactive subscription from it.
UpdateManager.ctorcreates instance of inner type calledObservablefor each type of request separate which subscribes inside its own constructor to internalIDictionary<UpdateTypeWrapper<UpdateType?>, List<object>>. Each subscription tryies to runRunUpdateSafemethod which has to be launched only once. Inside try catch block there are check if it runs only once. Then it calls theTask RunUpdatewhich runs until there at least 1 subscriber, that setups request and calls_telegramBot.GetUpdate(getUpdate, _cancellationTokenSource.Token);. Each second inside of the task it checks result. And at last it callsDistributeUpdatesmethods that usesList<Action<Update>>to spread recieved data from Telegram server. Where each action set by enum, and callsOnNextmethod. As a resault each second there are a lot of unnecessary calls of many methods and we have almost 500 lines of code that very hard to read.How to improve
ALL of those classes and methods could be collapsed in 2 much more smaller RX methods. Each type of request could be easily filtred from main stream when and only when it has subscribers.
So as you can see
Message1andCallbackQuery1properties do the same thatMessageandCallbackQueryrespectively do. In addition, a user can now connect to different bots at one stream usingLaunchermethod. I'm not sure if this feature is necessary for someone right now but it's just appeared by itself cause of RX approach. And as I said before, I didn't finished the code. I had problem with restoring request afterRefCountdrops to 0 and then a new subcriber appeares.A subscriptions to the current Updates produces periodic errors In my own project and the subscriptions were breaking. So I should figure out where I could handle this errors. And while I was delving into code I came to this solution. This draft code has been lying idle for 3 months now. That's why I decide to share my thoughts and code sample. I suppose that it will significantly improve memmory efficiency and code readability. Probably this change should slightly improve speed of code as well.
P.S. The subscription were breaking most time due to HTTP Request response error 502 from a host of my bot. So I make a workaround to restore connection. Perhaps it could be useful to someone.
Beta Was this translation helpful? Give feedback.
All reactions