Make generic version of batcher function (#3822)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "singletons/Toasts.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "widgets/Window.hpp"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -35,15 +36,6 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
|
||||
this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] {
|
||||
this->twitchSetting_.setValue(this->channelMap[Platform::Twitch].raw());
|
||||
});
|
||||
/*
|
||||
for (const QString &channelName : this->mixerSetting_.getValue()) {
|
||||
this->channelMap[Platform::Mixer].appendItem(channelName);
|
||||
}
|
||||
|
||||
this->channelMap[Platform::Mixer].delayedItemsChanged.connect([this] {
|
||||
this->mixerSetting_.setValue(
|
||||
this->channelMap[Platform::Mixer]);
|
||||
});*/
|
||||
|
||||
liveStatusTimer_ = new QTimer();
|
||||
|
||||
@@ -128,40 +120,12 @@ NotificationModel *NotificationController::createModel(QObject *parent,
|
||||
return model;
|
||||
}
|
||||
|
||||
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 NotificationController::fetchFakeChannels()
|
||||
{
|
||||
qCDebug(chatterinoNotification) << "fetching fake channels";
|
||||
QStringList channels;
|
||||
for (std::vector<int>::size_type i = 0;
|
||||
i != channelMap[Platform::Twitch].raw().size(); i++)
|
||||
i < channelMap[Platform::Twitch].raw().size(); i++)
|
||||
{
|
||||
auto chan = getApp()->twitch->getChannelOrEmpty(
|
||||
channelMap[Platform::Twitch].raw()[i]);
|
||||
@@ -170,10 +134,11 @@ void NotificationController::fetchFakeChannels()
|
||||
channels.push_back(channelMap[Platform::Twitch].raw()[i]);
|
||||
}
|
||||
}
|
||||
for (const auto &batch : getChannelsInBatches(channels))
|
||||
|
||||
for (const auto &batch : splitListIntoBatches(channels))
|
||||
{
|
||||
getHelix()->fetchStreams(
|
||||
QStringList(), batch,
|
||||
{}, batch,
|
||||
[batch, this](std::vector<HelixStream> streams) {
|
||||
std::unordered_set<QString> liveStreams;
|
||||
for (const auto &stream : streams)
|
||||
|
||||
Reference in New Issue
Block a user