mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Batch checking live status for all channels after startup. (#3757)
This commit is contained in:
parent
4239666934
commit
dc34c16dbe
|
@ -27,6 +27,7 @@
|
|||
- Bugfix: Fixed viewer list not closing after pressing escape key. (#3734)
|
||||
- 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: Batch checking live status for all channels after startup. (#3757)
|
||||
|
||||
## 2.3.5
|
||||
|
||||
|
|
|
@ -188,11 +188,6 @@ TwitchChannel::TwitchChannel(const QString &name)
|
|||
});
|
||||
this->chattersListTimer_.start(5 * 60 * 1000);
|
||||
|
||||
QObject::connect(&this->liveStatusTimer_, &QTimer::timeout, [=] {
|
||||
this->refreshLiveStatus();
|
||||
});
|
||||
this->liveStatusTimer_.start(60 * 1000);
|
||||
|
||||
// debugging
|
||||
#if 0
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
|
|
|
@ -193,7 +193,6 @@ private:
|
|||
// --
|
||||
QString lastSentMessage_;
|
||||
QObject lifetimeGuard_;
|
||||
QTimer liveStatusTimer_;
|
||||
QTimer chattersListTimer_;
|
||||
QElapsedTimer titleRefreshedTimer_;
|
||||
QElapsedTimer clipCreationTimer_;
|
||||
|
|
|
@ -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('#'))
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
|
||||
std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID);
|
||||
|
||||
void bulkRefreshLiveStatus();
|
||||
|
||||
Atomic<QString> lastUserThatWhisperedMe;
|
||||
|
||||
const ChannelPtr whispersChannel;
|
||||
|
@ -74,6 +76,7 @@ private:
|
|||
|
||||
BttvEmotes bttv;
|
||||
FfzEmotes ffz;
|
||||
QTimer bulkLiveStatusTimer_;
|
||||
|
||||
pajlada::Signals::SignalHolder signalHolder_;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue