Batch checking live status for all channels after startup. (#3757)

This commit is contained in:
xel86 2022-05-22 11:51:23 -04:00 committed by GitHub
parent 4239666934
commit dc34c16dbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 6 deletions

View file

@ -27,6 +27,7 @@
- Bugfix: Fixed viewer list not closing after pressing escape key. (#3734) - Bugfix: Fixed viewer list not closing after pressing escape key. (#3734)
- Bugfix: Fixed links with no thumbnail having previous link's thumbnail. (#3720) - Bugfix: Fixed links with no thumbnail having previous link's thumbnail. (#3720)
- Dev: Use Game Name returned by Get Streams instead of querying it from the Get Games API. (#3662) - Dev: Use Game Name returned by Get Streams instead of querying it from the Get Games API. (#3662)
- Dev: Batch checking live status for all channels after startup. (#3757)
## 2.3.5 ## 2.3.5

View file

@ -188,11 +188,6 @@ TwitchChannel::TwitchChannel(const QString &name)
}); });
this->chattersListTimer_.start(5 * 60 * 1000); this->chattersListTimer_.start(5 * 60 * 1000);
QObject::connect(&this->liveStatusTimer_, &QTimer::timeout, [=] {
this->refreshLiveStatus();
});
this->liveStatusTimer_.start(60 * 1000);
// debugging // debugging
#if 0 #if 0
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {

View file

@ -193,7 +193,6 @@ private:
// -- // --
QString lastSentMessage_; QString lastSentMessage_;
QObject lifetimeGuard_; QObject lifetimeGuard_;
QTimer liveStatusTimer_;
QTimer chattersListTimer_; QTimer chattersListTimer_;
QElapsedTimer titleRefreshedTimer_; QElapsedTimer titleRefreshedTimer_;
QElapsedTimer clipCreationTimer_; QElapsedTimer clipCreationTimer_;

View file

@ -53,6 +53,12 @@ void TwitchIrcServer::initialize(Settings &settings, Paths &paths)
this->bttv.loadEmotes(); this->bttv.loadEmotes();
this->ffz.loadEmotes(); this->ffz.loadEmotes();
/* Refresh all twitch channel's live status in bulk every 30 seconds after starting chatterino */
QObject::connect(&this->bulkLiveStatusTimer_, &QTimer::timeout, [=] {
this->bulkRefreshLiveStatus();
});
this->bulkLiveStatusTimer_.start(30 * 1000);
} }
void TwitchIrcServer::initializeConnection(IrcConnection *connection, void TwitchIrcServer::initializeConnection(IrcConnection *connection,
@ -296,6 +302,64 @@ std::shared_ptr<Channel> TwitchIrcServer::getChannelOrEmptyByID(
return Channel::getEmpty(); return Channel::getEmpty();
} }
namespace {
// TODO: combine this with getEmoteSetBatches in TwitchAccount.cpp, maybe some templated thing
std::vector<QStringList> getChannelsInBatches(QStringList channels)
{
constexpr int batchSize = 100;
int batchCount = (channels.size() / batchSize) + 1;
std::vector<QStringList> batches;
batches.reserve(batchCount);
for (int i = 0; i < batchCount; i++)
{
QStringList batch;
// I hate you, msvc
int last = (std::min)(batchSize, channels.size() - batchSize * i);
for (int j = 0; j < last; j++)
{
batch.push_back(channels.at(j + (batchSize * i)));
}
batches.emplace_back(batch);
}
return batches;
}
} // namespace
void TwitchIrcServer::bulkRefreshLiveStatus()
{
QStringList userIDs;
this->forEachChannel([&userIDs](ChannelPtr chan) {
auto twitchChan = dynamic_cast<TwitchChannel *>(chan.get());
if (!twitchChan->roomId().isEmpty())
userIDs.push_back(twitchChan->roomId());
});
for (const auto &batch : getChannelsInBatches(userIDs))
{
getHelix()->fetchStreams(
batch, QStringList(),
[this](std::vector<HelixStream> streams) {
for (const auto &stream : streams)
{
auto chan = this->getChannelOrEmptyByID(stream.userId);
if (chan->getType() != Channel::Type::Twitch)
continue;
auto twitchChan = dynamic_cast<TwitchChannel *>(chan.get());
twitchChan->parseLiveStatus(true, stream);
}
},
[]() {
// failure
});
}
}
QString TwitchIrcServer::cleanChannelName(const QString &dirtyChannelName) QString TwitchIrcServer::cleanChannelName(const QString &dirtyChannelName)
{ {
if (dirtyChannelName.startsWith('#')) if (dirtyChannelName.startsWith('#'))

View file

@ -31,6 +31,8 @@ public:
std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID); std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID);
void bulkRefreshLiveStatus();
Atomic<QString> lastUserThatWhisperedMe; Atomic<QString> lastUserThatWhisperedMe;
const ChannelPtr whispersChannel; const ChannelPtr whispersChannel;
@ -74,6 +76,7 @@ private:
BttvEmotes bttv; BttvEmotes bttv;
FfzEmotes ffz; FfzEmotes ffz;
QTimer bulkLiveStatusTimer_;
pajlada::Signals::SignalHolder signalHolder_; pajlada::Signals::SignalHolder signalHolder_;
}; };