2018-07-26 23:36:28 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-07-30 23:34:23 +03:00
|
|
|
#include "storage/cache/storage_cache_types.h"
|
|
|
|
#include "base/basic_types.h"
|
2018-07-26 23:36:28 +03:00
|
|
|
#include <crl/crl_object_on_queue.h>
|
2018-08-18 21:45:12 +03:00
|
|
|
#include <crl/crl_time.h>
|
2018-07-26 23:36:28 +03:00
|
|
|
#include <QtCore/QString>
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
class EncryptionKey;
|
|
|
|
namespace Cache {
|
|
|
|
namespace details {
|
2018-08-19 23:06:49 +03:00
|
|
|
class DatabaseObject;
|
2018-07-26 23:36:28 +03:00
|
|
|
} // namespace details
|
|
|
|
|
2018-08-19 23:06:49 +03:00
|
|
|
using Key = details::Key;
|
|
|
|
using Error = details::Error;
|
2018-07-29 00:08:29 +03:00
|
|
|
|
2018-07-26 23:36:28 +03:00
|
|
|
class Database {
|
|
|
|
public:
|
2018-07-29 00:08:29 +03:00
|
|
|
struct Settings {
|
2018-08-18 21:45:12 +03:00
|
|
|
size_type maxBundledRecords = 16 * 1024;
|
|
|
|
size_type readBlockSize = 8 * 1024 * 1024;
|
|
|
|
size_type maxDataSize = 10 * 1024 * 1024;
|
|
|
|
crl::time_type writeBundleDelay = 15 * 60 * crl::time_type(1000);
|
2018-08-19 18:32:48 +03:00
|
|
|
|
2018-08-19 23:06:49 +03:00
|
|
|
int64 compactAfterExcess = 8 * 1024 * 1024;
|
|
|
|
int64 compactAfterFullSize = 0;
|
|
|
|
|
2018-08-19 18:32:48 +03:00
|
|
|
bool trackEstimatedTime = true;
|
|
|
|
int64 totalSizeLimit = 1024 * 1024 * 1024;
|
|
|
|
size_type totalTimeLimit = 30 * 86400; // One month in seconds.
|
2018-08-18 21:45:12 +03:00
|
|
|
size_type maxTimeAdvancement = 365 * 86400; // One year in seconds.
|
|
|
|
crl::time_type pruneTimeout = 5 * crl::time_type(1000);
|
2018-08-19 18:32:48 +03:00
|
|
|
crl::time_type maxPruneCheckTimeout = 3600 * crl::time_type(1000);
|
2018-07-29 00:08:29 +03:00
|
|
|
};
|
|
|
|
Database(const QString &path, const Settings &settings);
|
|
|
|
|
|
|
|
void open(EncryptionKey key, FnMut<void(Error)> done);
|
|
|
|
void close(FnMut<void()> done);
|
|
|
|
|
|
|
|
void put(const Key &key, QByteArray value, FnMut<void(Error)> done);
|
|
|
|
void get(const Key &key, FnMut<void(QByteArray)> done);
|
|
|
|
void remove(const Key &key, FnMut<void()> done);
|
|
|
|
|
|
|
|
void clear(FnMut<void(Error)> done);
|
|
|
|
|
|
|
|
~Database();
|
2018-07-26 23:36:28 +03:00
|
|
|
|
|
|
|
private:
|
2018-08-19 23:06:49 +03:00
|
|
|
using Implementation = details::DatabaseObject;
|
2018-07-26 23:36:28 +03:00
|
|
|
crl::object_on_queue<Implementation> _wrapped;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Cache
|
|
|
|
} // namespace Storage
|