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

Use empty Storage::Cache::Key as nullopt.

This commit is contained in:
John Preston
2020-05-20 16:28:18 +04:00
parent 581a21dbd9
commit fb322b5fc5
20 changed files with 71 additions and 68 deletions

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;