2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Use crl::time/now instead of TimeMs/getms.

This commit is contained in:
John Preston
2019-02-19 10:57:53 +04:00
parent d208236994
commit fe618bd652
310 changed files with 1133 additions and 1141 deletions

View File

@@ -25,7 +25,7 @@ namespace Cache {
namespace details {
namespace {
constexpr auto kMaxDelayAfterFailure = 24 * 60 * 60 * crl::time_type(1000);
constexpr auto kMaxDelayAfterFailure = 24 * 60 * 60 * crl::time(1000);
uint32 CountChecksum(bytes::const_span data) {
const auto seed = uint32(0);
@@ -329,7 +329,7 @@ bool DatabaseObject::startDelayedPruning() {
const auto seconds = int64(_minimalEntryTime - before);
if (!_pruneTimer.isActive()) {
_pruneTimer.callOnce(std::min(
crl::time_type(seconds * 1000),
crl::time(seconds * 1000),
_settings.maxPruneCheckTimeout));
}
}
@@ -724,7 +724,7 @@ void DatabaseObject::compactorDone(
void DatabaseObject::compactorFail() {
const auto delay = _compactor.delayAfterFailure;
_compactor = CompactorWrap();
_compactor.nextAttempt = crl::time() + delay;
_compactor.nextAttempt = crl::now() + delay;
_compactor.delayAfterFailure = std::min(
delay * 2,
kMaxDelayAfterFailure);
@@ -868,7 +868,7 @@ std::optional<QString> DatabaseObject::writeKeyPlace(
const auto writing = record.time.getRelative();
const auto current = _time.getRelative();
Assert(writing >= current);
if ((writing - current) * crl::time_type(1000)
if ((writing - current) * crl::time(1000)
< _settings.writeBundleDelay) {
// We don't want to produce a lot of unique _time.relative values.
// So if change in it is not large we stick to the old value.
@@ -923,7 +923,7 @@ Error DatabaseObject::writeExistingPlace(
const auto writing = record.time.getRelative();
const auto current = _time.getRelative();
Assert(writing >= current);
if ((writing - current) * crl::time_type(1000)
if ((writing - current) * crl::time(1000)
< _settings.writeBundleDelay) {
// We don't want to produce a lot of unique _time.relative values.
// So if change in it is not large we stick to the old value.
@@ -1189,7 +1189,7 @@ void DatabaseObject::checkCompactor() {
&& (_binlogExcessLength * _settings.compactAfterFullSize
< _settings.compactAfterExcess * _binlog.size())) {
return;
} else if (crl::time() < _compactor.nextAttempt || !_binlog.isOpen()) {
} else if (crl::now() < _compactor.nextAttempt || !_binlog.isOpen()) {
return;
}
auto info = Compactor::Info();

View File

@@ -97,8 +97,8 @@ private:
struct CompactorWrap {
std::unique_ptr<Compactor> object;
int64 excessLength = 0;
crl::time_type nextAttempt = 0;
crl::time_type delayAfterFailure = 10 * crl::time_type(1000);
crl::time nextAttempt = 0;
crl::time delayAfterFailure = 10 * crl::time(1000);
base::binary_guard guard;
};
using Map = std::unordered_map<Key, Entry>;

View File

@@ -161,8 +161,8 @@ Error ClearByTag(Database &db, uint8 tag) {
const auto Settings = [] {
auto result = Database::Settings();
result.trackEstimatedTime = false;
result.writeBundleDelay = 1 * crl::time_type(1000);
result.pruneTimeout = 1 * crl::time_type(1500);
result.writeBundleDelay = 1 * crl::time(1000);
result.pruneTimeout = 1 * crl::time(1500);
result.maxDataSize = 20;
return result;
}();
@@ -221,7 +221,7 @@ TEST_CASE("compacting db", "[storage_cache_database]") {
};
SECTION("simple compact with min size") {
auto settings = Settings;
settings.writeBundleDelay = crl::time_type(100);
settings.writeBundleDelay = crl::time(100);
settings.readBlockSize = 512;
settings.maxBundledRecords = 5;
settings.compactAfterExcess = (3 * (16 * 5 + 16) + 15 * 32) / 2;
@@ -264,7 +264,7 @@ TEST_CASE("compacting db", "[storage_cache_database]") {
}
SECTION("simple compact without min size") {
auto settings = Settings;
settings.writeBundleDelay = crl::time_type(100);
settings.writeBundleDelay = crl::time(100);
settings.readBlockSize = 512;
settings.maxBundledRecords = 5;
settings.compactAfterExcess = 3 * (16 * 5 + 16) + 15 * 32;
@@ -304,7 +304,7 @@ TEST_CASE("compacting db", "[storage_cache_database]") {
}
SECTION("double compact") {
auto settings = Settings;
settings.writeBundleDelay = crl::time_type(100);
settings.writeBundleDelay = crl::time(100);
settings.readBlockSize = 512;
settings.maxBundledRecords = 5;
settings.compactAfterExcess = 3 * (16 * 5 + 16) + 15 * 32;
@@ -346,7 +346,7 @@ TEST_CASE("compacting db", "[storage_cache_database]") {
}
SECTION("time tracking compact") {
auto settings = Settings;
settings.writeBundleDelay = crl::time_type(100);
settings.writeBundleDelay = crl::time(100);
settings.trackEstimatedTime = true;
settings.readBlockSize = 512;
settings.maxBundledRecords = 5;
@@ -708,11 +708,11 @@ TEST_CASE("large db", "[storage_cache_database]") {
}
SECTION("time tracking large db") {
auto settings = Database::Settings();
settings.writeBundleDelay = crl::time_type(1000);
settings.writeBundleDelay = crl::time(1000);
settings.maxDataSize = 20;
settings.totalSizeLimit = 1024 * 1024;
settings.totalTimeLimit = 120;
settings.pruneTimeout = crl::time_type(1500);
settings.pruneTimeout = crl::time(1500);
settings.compactAfterExcess = 1024 * 1024;
settings.trackEstimatedTime = true;
Database db(name, settings);

View File

@@ -68,7 +68,7 @@ struct Settings {
size_type maxBundledRecords = 16 * 1024;
size_type readBlockSize = 8 * 1024 * 1024;
size_type maxDataSize = (kDataSizeLimit - 1);
crl::time_type writeBundleDelay = 15 * 60 * crl::time_type(1000);
crl::time writeBundleDelay = 15 * 60 * crl::time(1000);
size_type staleRemoveChunk = 256;
int64 compactAfterExcess = 8 * 1024 * 1024;
@@ -78,8 +78,8 @@ struct Settings {
bool trackEstimatedTime = true;
int64 totalSizeLimit = 1024 * 1024 * 1024;
size_type totalTimeLimit = 31 * 24 * 60 * 60; // One month in seconds.
crl::time_type pruneTimeout = 5 * crl::time_type(1000);
crl::time_type maxPruneCheckTimeout = 3600 * crl::time_type(1000);
crl::time pruneTimeout = 5 * crl::time(1000);
crl::time maxPruneCheckTimeout = 3600 * crl::time(1000);
bool clearOnWrongKey = false;
};

View File

@@ -25,7 +25,7 @@ namespace Storage {
namespace {
// How much time without download causes additional session kill.
constexpr auto kKillSessionTimeout = TimeMs(5000);
constexpr auto kKillSessionTimeout = crl::time(5000);
} // namespace
@@ -56,7 +56,7 @@ void Downloader::killDownloadSessionsStart(MTP::DcId dcId) {
if (!_killDownloadSessionTimes.contains(dcId)) {
_killDownloadSessionTimes.emplace(
dcId,
getms() + MTP::kAckSendWaiting + kKillSessionTimeout);
crl::now() + MTP::kAckSendWaiting + kKillSessionTimeout);
}
if (!_killDownloadSessionsTimer.isActive()) {
_killDownloadSessionsTimer.callOnce(
@@ -73,7 +73,7 @@ void Downloader::killDownloadSessionsStop(MTP::DcId dcId) {
}
void Downloader::killDownloadSessions() {
auto ms = getms(), left = MTP::kAckSendWaiting + kKillSessionTimeout;
auto ms = crl::now(), left = MTP::kAckSendWaiting + kKillSessionTimeout;
for (auto i = _killDownloadSessionTimes.begin(); i != _killDownloadSessionTimes.end(); ) {
if (i->second <= ms) {
for (int j = 0; j < MTP::kDownloadSessionsCount; ++j) {

View File

@@ -53,7 +53,7 @@ private:
using RequestedInDc = std::array<int64, MTP::kDownloadSessionsCount>;
std::map<MTP::DcId, RequestedInDc> _requestedBytesAmount;
base::flat_map<MTP::DcId, TimeMs> _killDownloadSessionTimes;
base::flat_map<MTP::DcId, crl::time> _killDownloadSessionTimes;
base::Timer _killDownloadSessionsTimer;
};

View File

@@ -39,10 +39,10 @@ constexpr auto kDocumentUploadPartSize3 = 256 * 1024;
constexpr auto kDocumentUploadPartSize4 = 512 * 1024;
// One part each half second, if not uploaded faster.
constexpr auto kUploadRequestInterval = TimeMs(500);
constexpr auto kUploadRequestInterval = crl::time(500);
// How much time without upload causes additional session kill.
constexpr auto kKillSessionTimeout = TimeMs(5000);
constexpr auto kKillSessionTimeout = crl::time(5000);
} // namespace

View File

@@ -299,7 +299,7 @@ SendMediaReady PrepareWallPaper(const QImage &image) {
0);
}
TaskQueue::TaskQueue(TimeMs stopTimeoutMs) {
TaskQueue::TaskQueue(crl::time stopTimeoutMs) {
if (stopTimeoutMs > 0) {
_stopTimer = new QTimer(this);
connect(_stopTimer, SIGNAL(timeout()), this, SLOT(stop()));

View File

@@ -105,7 +105,7 @@ class TaskQueue : public QObject {
Q_OBJECT
public:
explicit TaskQueue(TimeMs stopTimeoutMs = 0); // <= 0 - never stop worker
explicit TaskQueue(crl::time stopTimeoutMs = 0); // <= 0 - never stop worker
TaskId addTask(std::unique_ptr<Task> &&task);
void addTasks(std::vector<std::unique_ptr<Task>> &&tasks);

View File

@@ -44,10 +44,10 @@ namespace Local {
namespace {
constexpr auto kThemeFileSizeLimit = 5 * 1024 * 1024;
constexpr auto kFileLoaderQueueStopTimeout = TimeMs(5000);
constexpr auto kFileLoaderQueueStopTimeout = crl::time(5000);
constexpr auto kDefaultStickerInstallDate = TimeId(1);
constexpr auto kProxyTypeShift = 1024;
constexpr auto kWriteMapTimeout = TimeMs(1000);
constexpr auto kWriteMapTimeout = crl::time(1000);
constexpr auto kSavedBackgroundFormat = QImage::Format_ARGB32_Premultiplied;
constexpr auto kWallPaperLegacySerializeTagId = int32(-111);
@@ -2211,7 +2211,7 @@ void _readMtpData() {
}
ReadMapState _readMap(const QByteArray &pass) {
auto ms = getms();
auto ms = crl::now();
QByteArray dataNameUtf8 = (cDataFile() + (cTestMode() ? qsl(":/test/") : QString())).toUtf8();
FileKey dataNameHash[2];
hashMd5(dataNameUtf8.constData(), dataNameUtf8.size(), dataNameHash);
@@ -2412,7 +2412,7 @@ ReadMapState _readMap(const QByteArray &pass) {
std::move(selfSerialized),
_oldMapVersion);
LOG(("Map read time: %1").arg(getms() - ms));
LOG(("Map read time: %1").arg(crl::now() - ms));
if (_oldSettingsVersion < AppVersion) {
writeSettings();
}