2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 22:25:12 +00:00

Don't unload all media on switching between chats.

This commit is contained in:
John Preston
2018-10-23 16:57:43 +04:00
parent 959859f57c
commit 8e7117fa22
21 changed files with 61 additions and 83 deletions

View File

@@ -34,7 +34,7 @@ constexpr auto kMemoryForCache = 32 * 1024 * 1024;
Core::MediaActiveCache<DocumentData> &ActiveCache() {
static auto Instance = Core::MediaActiveCache<DocumentData>(
kMemoryForCache,
[](DocumentData *document) { document->forget(); });
[](DocumentData *document) { document->unload(); });
return Instance;
}
@@ -536,7 +536,9 @@ bool DocumentData::saveToCache() const {
|| (isVoiceMessage() && size < Storage::kMaxVoiceInMemory);
}
void DocumentData::forget() {
void DocumentData::unload() {
// Forget thumb only when image cache limit exceeds.
//thumb->unload();
if (sticker()) {
if (!sticker()->img->isNull()) {
ActiveCache().decrement(ComputeUsage(sticker()));
@@ -551,6 +553,7 @@ void DocumentData::forget() {
delete replyPreview.get();
replyPreview = ImagePtr();
}
ActiveCache().decrement(_data.size());
_data.clear();
}

View File

@@ -121,7 +121,7 @@ public:
void performActionOnLoad();
void forget();
void unload();
ImagePtr makeReplyPreview(Data::FileOrigin origin);
StickerData *sticker() const;

View File

@@ -30,11 +30,6 @@ struct GameData {
, document(document) {
}
void forget() {
if (document) document->forget();
if (photo) photo->forget();
}
GameId id = 0;
uint64 accessHash = 0;
QString shortName;

View File

@@ -103,15 +103,16 @@ bool PhotoData::uploading() const {
return (uploadingData != nullptr);
}
void PhotoData::forget() {
thumb->forget();
void PhotoData::unload() {
// Forget thumb only when image cache limit exceeds.
//thumb->unload();
medium->unload();
full->unload();
if (!replyPreview->isNull()) {
// Should be std::unique_ptr<Image>.
delete replyPreview.get();
replyPreview = ImagePtr();
}
medium->forget();
full->forget();
}
ImagePtr PhotoData::makeReplyPreview(Data::FileOrigin origin) {

View File

@@ -38,7 +38,7 @@ public:
void setWaitingForAlbum();
bool waitingForAlbum() const;
void forget();
void unload();
ImagePtr makeReplyPreview(Data::FileOrigin origin);
MTPInputPhoto mtpInput() const;

View File

@@ -2008,18 +2008,6 @@ void Session::insertCheckedServiceNotification(
sendHistoryChangeNotifications();
}
void Session::forgetMedia() {
for (const auto &[id, photo] : _photos) {
photo->forget();
}
for (const auto &[id, document] : _documents) {
document->forget();
}
for (const auto &[coords, location] : _locations) {
location->thumb->forget();
}
}
void Session::setMimeForwardIds(MessageIdsList &&list) {
_mimeForwardIds = std::move(list);
}

View File

@@ -420,8 +420,6 @@ public:
const TextWithEntities &message,
const MTPMessageMedia &media = MTP_messageMediaEmpty());
void forgetMedia();
void setMimeForwardIds(MessageIdsList &&list);
MessageIdsList takeMimeForwardIds();

View File

@@ -54,11 +54,6 @@ struct WebPageData {
, pendingTill(pendingTill) {
}
void forget() {
if (document) document->forget();
if (photo) photo->forget();
}
bool applyChanges(
const QString &newType,
const QString &newUrl,