Fix memory clearing from photos/documents.

This commit is contained in:
John Preston 2018-04-07 11:01:32 +04:00
parent 9895b45293
commit e5b2e0a6b5
6 changed files with 42 additions and 1 deletions

View File

@ -1628,6 +1628,7 @@ namespace {
int64 nowImageCacheSize = imageCacheSize();
if (nowImageCacheSize > serviceImageCacheSize + MemoryForImageCache) {
App::forgetMedia();
Auth().data().forgetMedia();
serviceImageCacheSize = imageCacheSize();
}
}

View File

@ -1778,6 +1778,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
if (_peer) {
App::forgetMedia();
Auth().data().forgetMedia();
_serviceImageCacheSize = imageCacheSize();
Auth().downloader().clearPriorities();

View File

@ -2880,6 +2880,10 @@ TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader) {
std::make_unique<ImageLoadTask>(j->first, location, loader));
}
bool willImageLoad(const StorageKey &location) {
return _imagesMap.constFind(location) != _imagesMap.cend();
}
int32 hasImages() {
return _imagesMap.size();
}
@ -3024,6 +3028,10 @@ bool copyAudio(const StorageKey &oldLocation, const StorageKey &newLocation) {
return true;
}
bool willAudioLoad(const StorageKey &location) {
return _audiosMap.constFind(location) != _audiosMap.cend();
}
int32 hasAudios() {
return _audiosMap.size();
}
@ -3130,6 +3138,10 @@ TaskId startWebFileLoad(const QString &url, webFileLoader *loader) {
std::make_unique<WebFileLoadTask>(j->first, url, loader));
}
bool willWebFileLoad(const QString &url) {
return _webFilesMap.constFind(url) != _webFilesMap.cend();
}
int32 hasWebFiles() {
return _webFilesMap.size();
}

View File

@ -95,6 +95,7 @@ FileLocation readFileLocation(MediaKey location, bool check = true);
void writeImage(const StorageKey &location, const ImagePtr &img);
void writeImage(const StorageKey &location, const StorageImageSaved &jpeg, bool overwrite = true);
TaskId startImageLoad(const StorageKey &location, mtpFileLoader *loader);
bool willImageLoad(const StorageKey &location);
int32 hasImages();
qint64 storageImagesSize();
@ -107,12 +108,14 @@ qint64 storageStickersSize();
void writeAudio(const StorageKey &location, const QByteArray &data, bool overwrite = true);
TaskId startAudioLoad(const StorageKey &location, mtpFileLoader *loader);
bool willAudioLoad(const StorageKey &location);
bool copyAudio(const StorageKey &oldLocation, const StorageKey &newLocation);
int32 hasAudios();
qint64 storageAudiosSize();
void writeWebFile(const QString &url, const QByteArray &data, bool overwrite = true);
TaskId startWebFileLoad(const QString &url, webFileLoader *loader);
bool willWebFileLoad(const QString &url);
int32 hasWebFiles();
qint64 storageWebFilesSize();

View File

@ -797,7 +797,9 @@ void Image::forget() const {
if (_data.isNull()) return;
invalidateSizeCache();
if (_saved.isEmpty()) {
/*if (hasLocalCopy()) {
_saved.clear();
} else */if (_saved.isEmpty()) {
QBuffer buffer(&_saved);
if (!_data.save(&buffer, _format)) {
if (_data.save(&buffer, "PNG")) {
@ -1030,6 +1032,10 @@ int32 StorageImage::countHeight() const {
return _location.height();
}
bool StorageImage::hasLocalCopy() const {
return Local::willImageLoad(storageKey(_location));
}
void StorageImage::setInformation(int32 size, int32 width, int32 height) {
_size = size;
_location.setSize(width, height);
@ -1070,6 +1076,10 @@ int WebFileImage::countHeight() const {
return _height;
}
bool WebFileImage::hasLocalCopy() const {
return Local::willImageLoad(storageKey(_location));
}
void WebFileImage::setInformation(int size, int width, int height) {
_size = size;
_width = width;
@ -1194,6 +1204,10 @@ int32 WebImage::countHeight() const {
return _height;
}
bool WebImage::hasLocalCopy() const {
return Local::willWebFileLoad(_url);
}
void WebImage::setInformation(int32 size, int32 width, int32 height) {
_size = size;
setSize(width, height);

View File

@ -324,6 +324,10 @@ protected:
return _data.height();
}
virtual bool hasLocalCopy() const {
return false;
}
mutable QByteArray _saved, _format;
mutable bool _forgot;
mutable QPixmap _data;
@ -413,6 +417,8 @@ protected:
void setInformation(int32 size, int32 width, int32 height) override;
FileLoader *createLoader(LoadFromCloudSetting fromCloud, bool autoLoading) override;
bool hasLocalCopy() const override;
StorageImageLocation _location;
int32 _size;
@ -434,6 +440,8 @@ protected:
return _box;
}
bool hasLocalCopy() const override;
WebFileLocation _location;
QSize _box;
int _width = 0;
@ -496,6 +504,8 @@ protected:
int32 countWidth() const override;
int32 countHeight() const override;
bool hasLocalCopy() const override;
private:
QString _url;
QSize _box;