Skip to content

Commit

Permalink
WIP: restore bulk update behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Oct 1, 2024
1 parent d2b1265 commit 3f22ea3
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/libserver/announcements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,33 +172,41 @@ void Announcements::timerEvent(QTimerEvent *event)
void Announcements::refreshListings()
{
using Update = QPair<Announcement, Session>;
using Updates = QVector<Update>;
using UpdatesByServer = QHash<QUrl, Updates>;

UpdatesByServer serverUpdates;
QSet<QUrl> refreshServers;
for(Listing &listing : m_announcements) {
bool shouldRefresh =
!refreshServers.contains(listing.listServer) &&
listing.finishedListing &&
(listing.refreshTimer.hasExpired(
listing.announcement.refreshInterval * 60 * 1000) ||
listing.session->hasUrgentAnnouncementChange(listing.description));
if(shouldRefresh) {
serverUpdates[listing.listServer].append(
{listing.announcement,
listing.session->getSessionAnnouncement()});
listing.refreshTimer.start();
refreshServers.insert(listing.listServer);
}
}

for(UpdatesByServer::const_iterator it = serverUpdates.constBegin(),
end = serverUpdates.constEnd();
it != end; ++it) {

const QUrl &refreshServer = it.key();
const Updates &updates = it.value();
for(QUrl refreshServer : refreshServers) {
QVector<Update> updates;
for(Listing &listing : m_announcements) {
if(listing.listServer == refreshServer) {
updates.append(
{listing.announcement,
listing.session->getSessionAnnouncement()});
listing.refreshTimer.start();
}
}

int updateCount = updates.size();
if(updateCount == 1) {
if(updateCount == 0) {
// Shouldn't happen.
server::Log()
.about(server::Log::Level::Error, server::Log::Topic::PubList)
.message(QStringLiteral("No announcements for server %1")
.arg(refreshServer.toString()))
.to(m_config->logger());
continue;
} else if(updateCount == 1) {
const Update &update = updates.first();
server::Log()
.about(server::Log::Level::Info, server::Log::Topic::PubList)
Expand Down

0 comments on commit 3f22ea3

Please sign in to comment.