Batch checking live status for all channels after startup. (#3757)
This commit is contained in:
@@ -53,6 +53,12 @@ void TwitchIrcServer::initialize(Settings &settings, Paths &paths)
|
||||
|
||||
this->bttv.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,
|
||||
@@ -296,6 +302,64 @@ std::shared_ptr<Channel> TwitchIrcServer::getChannelOrEmptyByID(
|
||||
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)
|
||||
{
|
||||
if (dirtyChannelName.startsWith('#'))
|
||||
|
||||
Reference in New Issue
Block a user