Merge pull request #10844 from Chocobo1/cache

Remove upper limit of disk cache setting
This commit is contained in:
Mike Tzou 2019-06-24 11:01:05 +08:00 committed by GitHub
commit 8d9b4a19bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 16 deletions

View file

@ -2840,22 +2840,19 @@ void Session::setCheckingMemUsage(int size)
int Session::diskCacheSize() const int Session::diskCacheSize() const
{ {
int size = m_diskCacheSize;
// These macros may not be available on compilers other than MSVC and GCC
#ifdef QBT_APP_64BIT #ifdef QBT_APP_64BIT
size = qMin(size, 4096); // 4GiB return qMin(m_diskCacheSize.value(), 33554431); // 32768GiB
#else #else
// When build as 32bit binary, set the maximum at less than 2GB to prevent crashes // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes
// allocate 1536MiB and leave 512MiB to the rest of program data in RAM // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
size = qMin(size, 1536); return qMin(m_diskCacheSize.value(), 1536);
#endif #endif
return size;
} }
void Session::setDiskCacheSize(int size) void Session::setDiskCacheSize(int size)
{ {
#ifdef QBT_APP_64BIT #ifdef QBT_APP_64BIT
size = qMin(size, 4096); // 4GiB size = qMin(size, 33554431); // 32768GiB
#else #else
// allocate 1536MiB and leave 512MiB to the rest of program data in RAM // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
size = qMin(size, 1536); size = qMin(size, 1536);

View file

@ -28,7 +28,6 @@
#include "random.h" #include "random.h"
#include <limits>
#include <random> #include <random>
#include <QtGlobal> #include <QtGlobal>

View file

@ -30,12 +30,13 @@
#define UTILS_RANDOM_H #define UTILS_RANDOM_H
#include <cstdint> #include <cstdint>
#include <limits>
namespace Utils namespace Utils
{ {
namespace Random namespace Random
{ {
uint32_t rand(uint32_t min = 0, uint32_t max = UINT32_MAX); uint32_t rand(uint32_t min = 0, uint32_t max = std::numeric_limits<uint32_t>::max());
} }
} }

View file

@ -342,9 +342,8 @@ void AdvancedSettings::loadAdvancedSettings()
// Disk write cache // Disk write cache
spinBoxCache.setMinimum(-1); spinBoxCache.setMinimum(-1);
// When build as 32bit binary, set the maximum at less than 2GB to prevent crashes. // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes.
// These macros may not be available on compilers other than MSVC and GCC
#ifdef QBT_APP_64BIT #ifdef QBT_APP_64BIT
spinBoxCache.setMaximum(4096); spinBoxCache.setMaximum(33554431); // 32768GiB
#else #else
// allocate 1536MiB and leave 512MiB to the rest of program data in RAM // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
spinBoxCache.setMaximum(1536); spinBoxCache.setMaximum(1536);
@ -354,8 +353,8 @@ void AdvancedSettings::loadAdvancedSettings()
addRow(DISK_CACHE, (tr("Disk cache") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#cache_size", "(?)")) addRow(DISK_CACHE, (tr("Disk cache") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#cache_size", "(?)"))
, &spinBoxCache); , &spinBoxCache);
// Disk cache expiry // Disk cache expiry
spinBoxCacheTTL.setMinimum(15); spinBoxCacheTTL.setMinimum(1);
spinBoxCacheTTL.setMaximum(600); spinBoxCacheTTL.setMaximum(std::numeric_limits<int>::max());
spinBoxCacheTTL.setValue(session->diskCacheTTL()); spinBoxCacheTTL.setValue(session->diskCacheTTL());
spinBoxCacheTTL.setSuffix(tr(" s", " seconds")); spinBoxCacheTTL.setSuffix(tr(" s", " seconds"));
addRow(DISK_CACHE_TTL, (tr("Disk cache expiry interval") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#cache_expiry", "(?)")) addRow(DISK_CACHE_TTL, (tr("Disk cache expiry interval") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#cache_expiry", "(?)"))
@ -378,19 +377,19 @@ void AdvancedSettings::loadAdvancedSettings()
, &checkBoxSuggestMode); , &checkBoxSuggestMode);
// Send buffer watermark // Send buffer watermark
spinBoxSendBufferWatermark.setMinimum(1); spinBoxSendBufferWatermark.setMinimum(1);
spinBoxSendBufferWatermark.setMaximum(INT_MAX); spinBoxSendBufferWatermark.setMaximum(std::numeric_limits<int>::max());
spinBoxSendBufferWatermark.setSuffix(tr(" KiB")); spinBoxSendBufferWatermark.setSuffix(tr(" KiB"));
spinBoxSendBufferWatermark.setValue(session->sendBufferWatermark()); spinBoxSendBufferWatermark.setValue(session->sendBufferWatermark());
addRow(SEND_BUF_WATERMARK, (tr("Send buffer watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark", "(?)")) addRow(SEND_BUF_WATERMARK, (tr("Send buffer watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark", "(?)"))
, &spinBoxSendBufferWatermark); , &spinBoxSendBufferWatermark);
spinBoxSendBufferLowWatermark.setMinimum(1); spinBoxSendBufferLowWatermark.setMinimum(1);
spinBoxSendBufferLowWatermark.setMaximum(INT_MAX); spinBoxSendBufferLowWatermark.setMaximum(std::numeric_limits<int>::max());
spinBoxSendBufferLowWatermark.setSuffix(tr(" KiB")); spinBoxSendBufferLowWatermark.setSuffix(tr(" KiB"));
spinBoxSendBufferLowWatermark.setValue(session->sendBufferLowWatermark()); spinBoxSendBufferLowWatermark.setValue(session->sendBufferLowWatermark());
addRow(SEND_BUF_LOW_WATERMARK, (tr("Send buffer low watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_low_watermark", "(?)")) addRow(SEND_BUF_LOW_WATERMARK, (tr("Send buffer low watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_low_watermark", "(?)"))
, &spinBoxSendBufferLowWatermark); , &spinBoxSendBufferLowWatermark);
spinBoxSendBufferWatermarkFactor.setMinimum(1); spinBoxSendBufferWatermarkFactor.setMinimum(1);
spinBoxSendBufferWatermarkFactor.setMaximum(INT_MAX); spinBoxSendBufferWatermarkFactor.setMaximum(std::numeric_limits<int>::max());
spinBoxSendBufferWatermarkFactor.setSuffix(" %"); spinBoxSendBufferWatermarkFactor.setSuffix(" %");
spinBoxSendBufferWatermarkFactor.setValue(session->sendBufferWatermarkFactor()); spinBoxSendBufferWatermarkFactor.setValue(session->sendBufferWatermarkFactor());
addRow(SEND_BUF_WATERMARK_FACTOR, (tr("Send buffer watermark factor") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark_factor", "(?)")) addRow(SEND_BUF_WATERMARK_FACTOR, (tr("Send buffer watermark factor") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark_factor", "(?)"))

View file

@ -28,6 +28,8 @@
#include "searchcontroller.h" #include "searchcontroller.h"
#include <limits>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QSharedPointer> #include <QSharedPointer>
@ -293,7 +295,7 @@ int SearchController::generateSearchId() const
while (true) while (true)
{ {
const auto id = Utils::Random::rand(1, INT_MAX); const int id = Utils::Random::rand(1, std::numeric_limits<int>::max());
if (!searchHandlers.contains(id)) if (!searchHandlers.contains(id))
return id; return id;
} }