mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
Two refinements to the per-host request caps: - Unlocked hosts (UNLIMITED_HOST_QUOTA, e.g. cards.scryfall.io) no longer wait on the 100ms dispatch pacing or consume the global per-second quota. dispatchQueuedRequest fires their queued requests back-to-back, bounded only by their 429 backoff window and Qt's per-host connection pool, so an unthrottled CDN is not artificially slowed. - The deck editor download settings page replaces the static grid of one spinbox per known host with an "Adjust Rate Limit" toolbar action on the URL list. It picks the host out of the selected URL and clamps the entry against the developer cap table (including for user-added URLs). Also fixes a review finding: resetRequestQuota could write the UNLIMITED_HOST_QUOTA sentinel (-1) into the sustained per-host quota when a host became unlocked mid-run, permanently poisoning its allowance. Stale entries for unlocked hosts are now dropped, and the per-second seed is clamped against the effective ceiling so a lowered limit applies immediately.
69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
/**
|
|
* @file download_settings.h
|
|
* @ingroup NetworkSettings
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef COCKATRICE_DOWNLOADSETTINGS_H
|
|
#define COCKATRICE_DOWNLOADSETTINGS_H
|
|
|
|
#include "settings_manager.h"
|
|
|
|
#include <QHash>
|
|
|
|
class DownloadSettings : public SettingsManager
|
|
{
|
|
Q_OBJECT
|
|
friend class SettingsCache;
|
|
|
|
static const QStringList DEFAULT_DOWNLOAD_URLS;
|
|
static const QHash<QString, int> DEVELOPER_HOST_CAPS;
|
|
|
|
public:
|
|
/** @brief Per-host request allowance (requests/second) when no developer cap applies. */
|
|
static constexpr int DEFAULT_HOST_REQUEST_LIMIT = 10;
|
|
/** @brief Floor for any per-host request allowance. */
|
|
static constexpr int MIN_HOST_REQUEST_LIMIT = 1;
|
|
/** @brief Developer cap marking a host as never throttled per host or by the dispatch pacing. */
|
|
static constexpr int UNLIMITED_HOST_QUOTA = -1;
|
|
|
|
/**
|
|
* @brief Developer-set per-host allowance ceilings (requests/second), keyed by host.
|
|
*
|
|
* Hosts not present default to DEFAULT_HOST_REQUEST_LIMIT. An entry of
|
|
* UNLIMITED_HOST_QUOTA marks a host that users may still lower, but that is never
|
|
* throttled per host by default. Users can never raise a host's allowance above its
|
|
* developer cap.
|
|
*/
|
|
static const QHash<QString, int> &getDeveloperHostCaps();
|
|
|
|
explicit DownloadSettings(const QString &, QObject *);
|
|
|
|
QStringList getAllURLs() const;
|
|
void setDownloadUrls(const QStringList &downloadURLs);
|
|
void resetToDefaultURLs();
|
|
[[nodiscard]] bool getPicDownload() const;
|
|
void setPicDownload(bool _picDownload);
|
|
[[nodiscard]] bool getDownloadSpoilersStatus() const;
|
|
void setDownloadSpoilerStatus(bool _spoilerStatus);
|
|
|
|
/** @brief User-set per-host request allowances (requests/second). Missing hosts use the developer default. */
|
|
QHash<QString, int> getHostRequestLimits() const;
|
|
void setHostRequestLimits(const QHash<QString, int> &hostRequestLimits);
|
|
|
|
/**
|
|
* @brief Clamps the user's requested allowance for a host against its developer cap.
|
|
* @param host The host to clamp for
|
|
* @param requested The user-requested allowance in requests/second
|
|
* @return The effective allowance. Users may lower a host's allowance but never raise it
|
|
* above the developer cap; hosts with UNLIMITED_HOST_QUOTA have no upper bound.
|
|
*/
|
|
[[nodiscard]] int clampHostRequestLimit(const QString &host, int requested) const;
|
|
|
|
signals:
|
|
void picDownloadChanged();
|
|
void downloadSpoilerStatusChanged();
|
|
void hostRequestLimitsChanged();
|
|
};
|
|
|
|
#endif // COCKATRICE_DOWNLOADSETTINGS_H
|