dev: Add RecentMessages benchmark (#5071)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2024-01-07 13:15:36 +01:00
committed by GitHub
parent 78a7ebb9f9
commit f42ae07408
22 changed files with 446 additions and 119 deletions
+5 -3
View File
@@ -32,9 +32,11 @@ bool isIgnoredMessage(IgnoredMessageParameters &&params)
{
auto sourceUserID = params.twitchUserID;
bool isBlocked =
getApp()->accounts->twitch.getCurrent()->blockedUserIds().contains(
sourceUserID);
bool isBlocked = getIApp()
->getAccounts()
->twitch.getCurrent()
->blockedUserIds()
.contains(sourceUserID);
if (isBlocked)
{
switch (static_cast<ShowIgnoredUsersMessages>(
+29 -30
View File
@@ -142,31 +142,33 @@ namespace {
return anyModifications;
}
std::pair<Outcome, EmoteMap> parseChannelEmotes(
const QJsonObject &jsonRoot, const QString &channelDisplayName)
{
auto emotes = EmoteMap();
auto innerParse = [&jsonRoot, &emotes,
&channelDisplayName](const char *key) {
auto jsonEmotes = jsonRoot.value(key).toArray();
for (auto jsonEmote_ : jsonEmotes)
{
auto emote = createChannelEmote(channelDisplayName,
jsonEmote_.toObject());
emotes[emote.name] =
cachedOrMake(std::move(emote.emote), emote.id);
}
};
innerParse("channelEmotes");
innerParse("sharedEmotes");
return {Success, std::move(emotes)};
}
} // namespace
using namespace bttv::detail;
EmoteMap bttv::detail::parseChannelEmotes(const QJsonObject &jsonRoot,
const QString &channelDisplayName)
{
auto emotes = EmoteMap();
auto innerParse = [&jsonRoot, &emotes,
&channelDisplayName](const char *key) {
auto jsonEmotes = jsonRoot.value(key).toArray();
for (auto jsonEmote_ : jsonEmotes)
{
auto emote =
createChannelEmote(channelDisplayName, jsonEmote_.toObject());
emotes[emote.name] = cachedOrMake(std::move(emote.emote), emote.id);
}
};
innerParse("channelEmotes");
innerParse("sharedEmotes");
return emotes;
}
//
// BttvEmotes
//
@@ -230,14 +232,11 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
.timeout(20000)
.onSuccess([callback = std::move(callback), channel, channelDisplayName,
manualRefresh](auto result) {
auto pair =
auto emotes =
parseChannelEmotes(result.parseJson(), channelDisplayName);
bool hasEmotes = false;
if (pair.first)
{
hasEmotes = !pair.second.empty();
callback(std::move(pair.second));
}
bool hasEmotes = !emotes.empty();
callback(std::move(emotes));
if (auto shared = channel.lock(); manualRefresh)
{
if (hasEmotes)
+9
View File
@@ -3,6 +3,8 @@
#include "common/Aliases.hpp"
#include "common/Atomic.hpp"
#include <QJsonObject>
#include <memory>
#include <optional>
@@ -15,6 +17,13 @@ class Channel;
struct BttvLiveUpdateEmoteUpdateAddMessage;
struct BttvLiveUpdateEmoteRemoveMessage;
namespace bttv::detail {
EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot,
const QString &channelDisplayName);
} // namespace bttv::detail
class BttvEmotes final
{
static constexpr const char *globalEmoteApiUrl =
+14 -11
View File
@@ -149,19 +149,22 @@ namespace {
return authorityBadge;
}
EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot)
{
auto emotes = EmoteMap();
for (const auto emoteSetRef : jsonRoot["sets"].toObject())
{
parseEmoteSetInto(emoteSetRef.toObject(), "Channel", emotes);
}
return emotes;
}
} // namespace
using namespace ffz::detail;
EmoteMap ffz::detail::parseChannelEmotes(const QJsonObject &jsonRoot)
{
auto emotes = EmoteMap();
for (const auto emoteSetRef : jsonRoot["sets"].toObject())
{
parseEmoteSetInto(emoteSetRef.toObject(), "Channel", emotes);
}
return emotes;
}
FfzEmotes::FfzEmotes()
: global_(std::make_shared<EmoteMap>())
{
+8
View File
@@ -3,6 +3,8 @@
#include "common/Aliases.hpp"
#include "common/Atomic.hpp"
#include <QJsonObject>
#include <memory>
#include <optional>
@@ -13,6 +15,12 @@ using EmotePtr = std::shared_ptr<const Emote>;
class EmoteMap;
class Channel;
namespace ffz::detail {
EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot);
} // namespace ffz::detail
class FfzEmotes final
{
public:
+28 -26
View File
@@ -128,7 +128,34 @@ bool checkEmoteVisibility(const QJsonObject &emoteData)
return !flags.has(SeventvEmoteFlag::ContentTwitchDisallowed);
}
EmoteMap parseEmotes(const QJsonArray &emoteSetEmotes, bool isGlobal)
EmotePtr createUpdatedEmote(const EmotePtr &oldEmote,
const EmoteUpdateDispatch &dispatch)
{
bool toNonAliased = oldEmote->baseName.has_value() &&
dispatch.emoteName == oldEmote->baseName->string;
auto baseName = oldEmote->baseName.value_or(oldEmote->name);
auto emote = std::make_shared<const Emote>(Emote(
{EmoteName{dispatch.emoteName}, oldEmote->images,
toNonAliased
? createTooltip(dispatch.emoteName, oldEmote->author.string, false)
: createAliasedTooltip(dispatch.emoteName, baseName.string,
oldEmote->author.string, false),
oldEmote->homePage, oldEmote->zeroWidth, oldEmote->id,
oldEmote->author, makeConditionedOptional(!toNonAliased, baseName)}));
return emote;
}
} // namespace
namespace chatterino {
using namespace seventv::eventapi;
using namespace seventv::detail;
using namespace literals;
EmoteMap seventv::detail::parseEmotes(const QJsonArray &emoteSetEmotes,
bool isGlobal)
{
auto emotes = EmoteMap();
@@ -158,31 +185,6 @@ EmoteMap parseEmotes(const QJsonArray &emoteSetEmotes, bool isGlobal)
return emotes;
}
EmotePtr createUpdatedEmote(const EmotePtr &oldEmote,
const EmoteUpdateDispatch &dispatch)
{
bool toNonAliased = oldEmote->baseName.has_value() &&
dispatch.emoteName == oldEmote->baseName->string;
auto baseName = oldEmote->baseName.value_or(oldEmote->name);
auto emote = std::make_shared<const Emote>(Emote(
{EmoteName{dispatch.emoteName}, oldEmote->images,
toNonAliased
? createTooltip(dispatch.emoteName, oldEmote->author.string, false)
: createAliasedTooltip(dispatch.emoteName, baseName.string,
oldEmote->author.string, false),
oldEmote->homePage, oldEmote->zeroWidth, oldEmote->id,
oldEmote->author, makeConditionedOptional(!toNonAliased, baseName)}));
return emote;
}
} // namespace
namespace chatterino {
using namespace seventv::eventapi;
using namespace literals;
SeventvEmotes::SeventvEmotes()
: global_(std::make_shared<EmoteMap>())
{
+7
View File
@@ -4,6 +4,7 @@
#include "common/Atomic.hpp"
#include "common/FlagsEnum.hpp"
#include <QJsonArray>
#include <QJsonObject>
#include <memory>
@@ -77,6 +78,12 @@ enum class SeventvEmoteSetFlag : uint32_t {
};
using SeventvEmoteSetFlags = FlagsEnum<SeventvEmoteSetFlag>;
namespace seventv::detail {
EmoteMap parseEmotes(const QJsonArray &emoteSetEmotes, bool isGlobal);
} // namespace seventv::detail
class SeventvEmotes final
{
public:
+1 -1
View File
@@ -128,7 +128,7 @@ void updateReplyParticipatedStatus(const QVariantMap &tags,
bool isNew)
{
const auto &currentLogin =
getApp()->accounts->twitch.getCurrent()->getUserName();
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
if (thread->subscribed())
{
+6
View File
@@ -29,6 +29,12 @@ void TwitchBadges::loadTwitchBadges()
{
assert(this->loaded_ == false);
if (!getHelix())
{
// This is intended for tests and benchmarks.
return;
}
getHelix()->getGlobalBadges(
[this](auto globalBadges) {
auto badgeSets = this->badgeSets_.access();
+46 -10
View File
@@ -87,6 +87,13 @@ TwitchChannel::TwitchChannel(const QString &name)
{
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";
if (!getApp())
{
// This is intended for tests and benchmarks.
// Irc, Pubsub, live-updates, and live-notifications aren't mocked there.
return;
}
this->bSignals_.emplace_back(
getApp()->accounts->twitch.currentUserChanged.connect([this] {
this->setMod(false);
@@ -219,6 +226,13 @@ TwitchChannel::TwitchChannel(const QString &name)
TwitchChannel::~TwitchChannel()
{
if (!getApp())
{
// This is for tests and benchmarks, where live-updates aren't mocked
// see comment in constructor.
return;
}
getApp()->twitch->dropSeventvChannel(this->seventvUserID_,
this->seventvEmoteSetID_);
@@ -282,8 +296,9 @@ void TwitchChannel::refreshBTTVChannelEmotes(bool manualRefresh)
weakOf<Channel>(this), this->roomId(), this->getLocalizedName(),
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
if (auto shared = weak.lock())
this->bttvEmotes_.set(
std::make_shared<EmoteMap>(std::move(emoteMap)));
{
this->setBttvEmotes(std::make_shared<const EmoteMap>(emoteMap));
}
},
manualRefresh);
}
@@ -300,8 +315,9 @@ void TwitchChannel::refreshFFZChannelEmotes(bool manualRefresh)
weakOf<Channel>(this), this->roomId(),
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
if (auto shared = weak.lock())
this->ffzEmotes_.set(
std::make_shared<EmoteMap>(std::move(emoteMap)));
{
this->setFfzEmotes(std::make_shared<const EmoteMap>(emoteMap));
}
},
[this, weak = weakOf<Channel>(this)](auto &&modBadge) {
if (auto shared = weak.lock())
@@ -332,8 +348,8 @@ void TwitchChannel::refreshSevenTVChannelEmotes(bool manualRefresh)
auto channelInfo) {
if (auto shared = weak.lock())
{
this->seventvEmotes_.set(std::make_shared<EmoteMap>(
std::forward<decltype(emoteMap)>(emoteMap)));
this->setSeventvEmotes(
std::make_shared<const EmoteMap>(emoteMap));
this->updateSeventvData(channelInfo.userID,
channelInfo.emoteSetID);
this->seventvUserTwitchConnectionIndex_ =
@@ -343,6 +359,21 @@ void TwitchChannel::refreshSevenTVChannelEmotes(bool manualRefresh)
manualRefresh);
}
void TwitchChannel::setBttvEmotes(std::shared_ptr<const EmoteMap> &&map)
{
this->bttvEmotes_.set(std::move(map));
}
void TwitchChannel::setFfzEmotes(std::shared_ptr<const EmoteMap> &&map)
{
this->ffzEmotes_.set(std::move(map));
}
void TwitchChannel::setSeventvEmotes(std::shared_ptr<const EmoteMap> &&map)
{
this->seventvEmotes_.set(std::move(map));
}
void TwitchChannel::addQueuedRedemption(const QString &rewardId,
const QString &originalContent,
Communi::IrcMessage *message)
@@ -700,9 +731,10 @@ void TwitchChannel::setStaff(bool value)
bool TwitchChannel::isBroadcaster() const
{
auto app = getApp();
auto *app = getIApp();
return this->getName() == app->accounts->twitch.getCurrent()->getUserName();
return this->getName() ==
app->getAccounts()->twitch.getCurrent()->getUserName();
}
bool TwitchChannel::hasHighRateLimit() const
@@ -730,8 +762,12 @@ void TwitchChannel::setRoomId(const QString &id)
if (*this->roomID_.accessConst() != id)
{
*this->roomID_.access() = id;
this->roomIdChanged();
this->loadRecentMessages();
// This is intended for tests and benchmarks. See comment in constructor.
if (getApp())
{
this->roomIdChanged();
this->loadRecentMessages();
}
this->disconnected_ = false;
this->lastConnectedAt_ = std::chrono::system_clock::now();
}
+4
View File
@@ -158,6 +158,10 @@ public:
void refreshFFZChannelEmotes(bool manualRefresh);
void refreshSevenTVChannelEmotes(bool manualRefresh);
void setBttvEmotes(std::shared_ptr<const EmoteMap> &&map);
void setFfzEmotes(std::shared_ptr<const EmoteMap> &&map);
void setSeventvEmotes(std::shared_ptr<const EmoteMap> &&map);
const QString &seventvUserID() const;
const QString &seventvEmoteSetID() const;