mirror of https://github.com/procxx/kepka.git
Use empty Storage::Cache::Key as nullopt.
This commit is contained in:
parent
581a21dbd9
commit
fb322b5fc5
|
@ -1162,7 +1162,7 @@ auto LottieFromDocument(
|
|||
if (const auto baseKey = document->bigFileBaseCacheKey()) {
|
||||
return LottieCachedFromContent(
|
||||
std::forward<Method>(method),
|
||||
*baseKey,
|
||||
baseKey,
|
||||
keyShift,
|
||||
&document->session(),
|
||||
Lottie::ReadContent(data, filepath),
|
||||
|
@ -1239,7 +1239,7 @@ bool HasLottieThumbnail(
|
|||
if (!media->loaded()) {
|
||||
return false;
|
||||
}
|
||||
return document->bigFileBaseCacheKey().has_value();
|
||||
return document->bigFileBaseCacheKey().valid();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1269,7 +1269,7 @@ std::unique_ptr<Lottie::SinglePlayer> LottieThumbnail(
|
|||
};
|
||||
return LottieCachedFromContent(
|
||||
method,
|
||||
*baseKey,
|
||||
baseKey,
|
||||
uint8(sizeTag),
|
||||
&document->session(),
|
||||
content,
|
||||
|
|
|
@ -141,7 +141,7 @@ public:
|
|||
|
||||
const StorageImageLocation &location() override;
|
||||
void refreshFileReference(const QByteArray &data) override;
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
Storage::Cache::Key cacheKey() override;
|
||||
void setDelayedStorageLocation(
|
||||
const StorageImageLocation &location) override;
|
||||
void performDelayedLoad(Data::FileOrigin origin) override;
|
||||
|
@ -256,8 +256,8 @@ const StorageImageLocation &ImageSource::location() {
|
|||
void ImageSource::refreshFileReference(const QByteArray &data) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> ImageSource::cacheKey() {
|
||||
return std::nullopt;
|
||||
Storage::Cache::Key ImageSource::cacheKey() {
|
||||
return {};
|
||||
}
|
||||
|
||||
void ImageSource::setDelayedStorageLocation(
|
||||
|
|
|
@ -627,7 +627,11 @@ void DocumentData::updateThumbnails(
|
|||
loadThumbnail(origin);
|
||||
}
|
||||
if (!thumbnail.bytes.isEmpty()) {
|
||||
// #TODO optimize put to cache
|
||||
owner().cache().putIfEmpty(
|
||||
_thumbnailLocation.file().cacheKey(),
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
base::duplicate(thumbnail.bytes),
|
||||
Data::kImageCacheTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -761,19 +765,17 @@ PhotoData *DocumentData::goodThumbnailPhoto() const {
|
|||
return _goodThumbnailPhoto;
|
||||
}
|
||||
|
||||
auto DocumentData::bigFileBaseCacheKey() const
|
||||
-> std::optional<Storage::Cache::Key> {
|
||||
if (hasRemoteLocation()) {
|
||||
return StorageFileLocation(
|
||||
Storage::Cache::Key DocumentData::bigFileBaseCacheKey() const {
|
||||
return hasRemoteLocation()
|
||||
? StorageFileLocation(
|
||||
_dc,
|
||||
session().userId(),
|
||||
MTP_inputDocumentFileLocation(
|
||||
MTP_long(id),
|
||||
MTP_long(_access),
|
||||
MTP_bytes(_fileReference),
|
||||
MTP_string())).bigFileBaseCacheKey();
|
||||
}
|
||||
return std::nullopt;
|
||||
MTP_string())).bigFileBaseCacheKey()
|
||||
: Storage::Cache::Key();
|
||||
}
|
||||
|
||||
bool DocumentData::saveToCache() const {
|
||||
|
@ -786,12 +788,6 @@ bool DocumentData::saveToCache() const {
|
|||
}
|
||||
|
||||
void DocumentData::unload() {
|
||||
// Forget thumb only when image cache limit exceeds.
|
||||
//
|
||||
// Also, you can't unload() images that you don't own
|
||||
// from the destructor, because they're already destroyed.
|
||||
//
|
||||
//_thumbnail->unload();
|
||||
_replyPreview = nullptr;
|
||||
}
|
||||
|
||||
|
@ -1333,14 +1329,6 @@ void DocumentData::refreshFileReference(const QByteArray &value) {
|
|||
_thumbnailLocation.refreshFileReference(value);
|
||||
}
|
||||
|
||||
void DocumentData::refreshStickerThumbFileReference() {
|
||||
// #TODO optimize
|
||||
//if (_thumbnailLoader) {
|
||||
// _thumbnailLocation.refreshFileReference(
|
||||
// _thumbnailLoader->fileReference());
|
||||
//}
|
||||
}
|
||||
|
||||
QString DocumentData::filename() const {
|
||||
return _filename;
|
||||
}
|
||||
|
|
|
@ -182,8 +182,7 @@ public:
|
|||
void setGoodThumbnailPhoto(not_null<PhotoData*> photo);
|
||||
[[nodiscard]] PhotoData *goodThumbnailPhoto() const;
|
||||
|
||||
[[nodiscard]] auto bigFileBaseCacheKey() const
|
||||
-> std::optional<Storage::Cache::Key>;
|
||||
[[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const;
|
||||
|
||||
void setRemoteLocation(
|
||||
int32 dc,
|
||||
|
@ -197,7 +196,6 @@ public:
|
|||
[[nodiscard]] MTPInputDocument mtpInput() const;
|
||||
[[nodiscard]] QByteArray fileReference() const;
|
||||
void refreshFileReference(const QByteArray &value);
|
||||
void refreshStickerThumbFileReference();
|
||||
|
||||
// When we have some client-side generated document
|
||||
// (for example for displaying an external inline bot result)
|
||||
|
|
|
@ -155,7 +155,7 @@ void PhotoData::collectLocalData(not_null<PhotoData*> local) {
|
|||
const auto copyImage = [&](const ImagePtr &src, const ImagePtr &dst) {
|
||||
if (const auto from = src->cacheKey()) {
|
||||
if (const auto to = dst->cacheKey()) {
|
||||
_owner->cache().copyIfEmpty(*from, *to);
|
||||
_owner->cache().copyIfEmpty(from, to);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -27,8 +27,7 @@ class Loader {
|
|||
public:
|
||||
static constexpr auto kPartSize = 128 * 1024;
|
||||
|
||||
[[nodiscard]] virtual auto baseCacheKey() const
|
||||
-> std::optional<Storage::Cache::Key> = 0;
|
||||
[[nodiscard]] virtual Storage::Cache::Key baseCacheKey() const = 0;
|
||||
[[nodiscard]] virtual int size() const = 0;
|
||||
|
||||
virtual void load(int offset) = 0;
|
||||
|
|
|
@ -34,8 +34,8 @@ LoaderLocal::LoaderLocal(std::unique_ptr<QIODevice> device)
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> LoaderLocal::baseCacheKey() const {
|
||||
return std::nullopt;
|
||||
Storage::Cache::Key LoaderLocal::baseCacheKey() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
int LoaderLocal::size() const {
|
||||
|
|
|
@ -20,8 +20,7 @@ class LoaderLocal : public Loader, public base::has_weak_ptr {
|
|||
public:
|
||||
LoaderLocal(std::unique_ptr<QIODevice> device);
|
||||
|
||||
[[nodiscard]] auto baseCacheKey() const
|
||||
->std::optional<Storage::Cache::Key> override;
|
||||
[[nodiscard]] Storage::Cache::Key baseCacheKey() const override;
|
||||
[[nodiscard]] int size() const override;
|
||||
|
||||
void load(int offset) override;
|
||||
|
|
|
@ -30,7 +30,7 @@ LoaderMtproto::LoaderMtproto(
|
|||
, _api(api().instance()) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> LoaderMtproto::baseCacheKey() const {
|
||||
Storage::Cache::Key LoaderMtproto::baseCacheKey() const {
|
||||
return location().data.get<StorageFileLocation>().bigFileBaseCacheKey();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ public:
|
|||
int size,
|
||||
Data::FileOrigin origin);
|
||||
|
||||
[[nodiscard]] auto baseCacheKey() const
|
||||
-> std::optional<Storage::Cache::Key> override;
|
||||
[[nodiscard]] Storage::Cache::Key baseCacheKey() const override;
|
||||
[[nodiscard]] int size() const override;
|
||||
|
||||
void load(int offset) override;
|
||||
|
|
|
@ -1109,15 +1109,15 @@ void Reader::refreshLoaderPriority() {
|
|||
}
|
||||
|
||||
bool Reader::isRemoteLoader() const {
|
||||
return _loader->baseCacheKey().has_value();
|
||||
return _loader->baseCacheKey().valid();
|
||||
}
|
||||
|
||||
std::shared_ptr<Reader::CacheHelper> Reader::InitCacheHelper(
|
||||
std::optional<Storage::Cache::Key> baseKey) {
|
||||
Storage::Cache::Key baseKey) {
|
||||
if (!baseKey) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_shared<Reader::CacheHelper>(*baseKey);
|
||||
return std::make_shared<Reader::CacheHelper>(baseKey);
|
||||
}
|
||||
|
||||
// 0 is for headerData, slice index = sliceNumber - 1.
|
||||
|
|
|
@ -226,7 +226,7 @@ private:
|
|||
void refreshLoaderPriority();
|
||||
|
||||
static std::shared_ptr<CacheHelper> InitCacheHelper(
|
||||
std::optional<Storage::Cache::Key> baseKey);
|
||||
Storage::Cache::Key baseKey);
|
||||
|
||||
const std::unique_ptr<Loader> _loader;
|
||||
Storage::Cache::Database * const _cache = nullptr;
|
||||
|
|
|
@ -3518,7 +3518,6 @@ void _writeStickerSets(FileKey &stickersKey, CheckSet checkSet, const Stickers::
|
|||
}
|
||||
|
||||
for (const auto sticker : set.stickers) {
|
||||
sticker->refreshStickerThumbFileReference();
|
||||
size += Serialize::Document::sizeInStream(sticker);
|
||||
}
|
||||
|
||||
|
|
|
@ -966,7 +966,7 @@ void Image::loadEvenCancelled(Data::FileOrigin origin) {
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> Image::cacheKey() const {
|
||||
Storage::Cache::Key Image::cacheKey() const {
|
||||
return _source->cacheKey();
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public:
|
|||
|
||||
virtual const StorageImageLocation &location() = 0;
|
||||
virtual void refreshFileReference(const QByteArray &data) = 0;
|
||||
virtual std::optional<Storage::Cache::Key> cacheKey() = 0;
|
||||
virtual Storage::Cache::Key cacheKey() = 0;
|
||||
virtual void setDelayedStorageLocation(
|
||||
const StorageImageLocation &location) = 0;
|
||||
virtual void performDelayedLoad(Data::FileOrigin origin) = 0;
|
||||
|
@ -220,7 +220,7 @@ public:
|
|||
void refreshFileReference(const QByteArray &data) {
|
||||
_source->refreshFileReference(data);
|
||||
}
|
||||
std::optional<Storage::Cache::Key> cacheKey() const;
|
||||
Storage::Cache::Key cacheKey() const;
|
||||
QByteArray bytesForCache() const {
|
||||
return _source->bytesForCache();
|
||||
}
|
||||
|
|
|
@ -776,6 +776,26 @@ DownloadLocation DownloadLocation::convertToModern(
|
|||
return DownloadLocation{ file.convertToModern(type, id, accessHash) };
|
||||
}
|
||||
|
||||
Storage::Cache::Key DownloadLocation::cacheKey() const {
|
||||
return data.match([](const GeoPointLocation &data) {
|
||||
return Data::GeoPointCacheKey(data);
|
||||
}, [](const StorageFileLocation &data) {
|
||||
return data.valid()
|
||||
? data.cacheKey()
|
||||
: Storage::Cache::Key();
|
||||
}, [](const WebFileLocation &data) {
|
||||
return data.isNull()
|
||||
? Storage::Cache::Key()
|
||||
: Data::WebDocumentCacheKey(data);
|
||||
}, [](const PlainUrlLocation &data) {
|
||||
return data.url.isEmpty()
|
||||
? Storage::Cache::Key()
|
||||
: Data::UrlCacheKey(data.url);
|
||||
}, [](const InMemoryLocation &data) {
|
||||
return Storage::Cache::Key();
|
||||
});
|
||||
}
|
||||
|
||||
bool DownloadLocation::valid() const {
|
||||
return data.match([](const GeoPointLocation &data) {
|
||||
return true;
|
||||
|
|
|
@ -411,6 +411,7 @@ public:
|
|||
uint64 id,
|
||||
uint64 accessHash) const;
|
||||
|
||||
[[nodiscard]] Storage::Cache::Key cacheKey() const;
|
||||
[[nodiscard]] bool valid() const;
|
||||
[[nodiscard]] QByteArray fileReference() const;
|
||||
bool refreshFileReference(const QByteArray &data);
|
||||
|
|
|
@ -91,8 +91,8 @@ const StorageImageLocation &ImageSource::location() {
|
|||
void ImageSource::refreshFileReference(const QByteArray &data) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> ImageSource::cacheKey() {
|
||||
return std::nullopt;
|
||||
Storage::Cache::Key ImageSource::cacheKey() {
|
||||
return Storage::Cache::Key();
|
||||
}
|
||||
|
||||
void ImageSource::setDelayedStorageLocation(
|
||||
|
@ -220,8 +220,8 @@ const StorageImageLocation &LocalFileSource::location() {
|
|||
void LocalFileSource::refreshFileReference(const QByteArray &data) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> LocalFileSource::cacheKey() {
|
||||
return std::nullopt;
|
||||
Storage::Cache::Key LocalFileSource::cacheKey() {
|
||||
return Storage::Cache::Key();
|
||||
}
|
||||
|
||||
void LocalFileSource::setDelayedStorageLocation(
|
||||
|
@ -455,10 +455,10 @@ const StorageImageLocation &StorageSource::location() {
|
|||
return _location;
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> StorageSource::cacheKey() {
|
||||
Storage::Cache::Key StorageSource::cacheKey() {
|
||||
return _location.valid()
|
||||
? base::make_optional(_location.file().cacheKey())
|
||||
: std::nullopt;
|
||||
? _location.file().cacheKey()
|
||||
: Storage::Cache::Key();
|
||||
}
|
||||
|
||||
int StorageSource::width() {
|
||||
|
@ -524,10 +524,10 @@ WebCachedSource::WebCachedSource(
|
|||
, _size(size) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> WebCachedSource::cacheKey() {
|
||||
Storage::Cache::Key WebCachedSource::cacheKey() {
|
||||
return _location.isNull()
|
||||
? std::nullopt
|
||||
: base::make_optional(Data::WebDocumentCacheKey(_location));
|
||||
? Storage::Cache::Key()
|
||||
: Data::WebDocumentCacheKey(_location);
|
||||
}
|
||||
|
||||
int WebCachedSource::width() {
|
||||
|
@ -574,7 +574,7 @@ GeoPointSource::GeoPointSource(const GeoPointLocation &location)
|
|||
: _location(location) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> GeoPointSource::cacheKey() {
|
||||
Storage::Cache::Key GeoPointSource::cacheKey() {
|
||||
return Data::GeoPointCacheKey(_location);
|
||||
}
|
||||
|
||||
|
@ -712,7 +712,7 @@ WebUrlSource::WebUrlSource(const QString &url, int width, int height)
|
|||
, _height(height) {
|
||||
}
|
||||
|
||||
std::optional<Storage::Cache::Key> WebUrlSource::cacheKey() {
|
||||
Storage::Cache::Key WebUrlSource::cacheKey() {
|
||||
return Data::UrlCacheKey(_url);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
|
||||
const StorageImageLocation &location() override;
|
||||
void refreshFileReference(const QByteArray &data) override;
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
Storage::Cache::Key cacheKey() override;
|
||||
void setDelayedStorageLocation(
|
||||
const StorageImageLocation &location) override;
|
||||
void performDelayedLoad(Data::FileOrigin origin) override;
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
const StorageImageLocation &location() override;
|
||||
void refreshFileReference(const QByteArray &data) override;
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
Storage::Cache::Key cacheKey() override;
|
||||
void setDelayedStorageLocation(
|
||||
const StorageImageLocation &location) override;
|
||||
void performDelayedLoad(Data::FileOrigin origin) override;
|
||||
|
@ -168,7 +168,7 @@ public:
|
|||
int size);
|
||||
|
||||
const StorageImageLocation &location() override;
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
Storage::Cache::Key cacheKey() override;
|
||||
|
||||
void refreshFileReference(const QByteArray &data) override;
|
||||
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
int height,
|
||||
int size = 0);
|
||||
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
Storage::Cache::Key cacheKey() override;
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
|
@ -224,7 +224,7 @@ class GeoPointSource : public RemoteSource {
|
|||
public:
|
||||
GeoPointSource(const GeoPointLocation &location);
|
||||
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
Storage::Cache::Key cacheKey() override;
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
|
@ -283,7 +283,7 @@ public:
|
|||
explicit WebUrlSource(const QString &url, QSize box = QSize());
|
||||
WebUrlSource(const QString &url, int width, int height);
|
||||
|
||||
std::optional<Storage::Cache::Key> cacheKey() override;
|
||||
Storage::Cache::Key cacheKey() override;
|
||||
|
||||
int width() override;
|
||||
int height() override;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 57027c7d6c071f0d958576a530c7c0411d8d4274
|
||||
Subproject commit df60834eac1545201682b2b55444c5ef61a170d2
|
Loading…
Reference in New Issue