mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
Don't unload all media on switching between chats.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
@@ -121,7 +121,7 @@ public:
|
||||
|
||||
void performActionOnLoad();
|
||||
|
||||
void forget();
|
||||
void unload();
|
||||
ImagePtr makeReplyPreview(Data::FileOrigin origin);
|
||||
|
||||
StickerData *sticker() const;
|
||||
|
@@ -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;
|
||||
|
@@ -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) {
|
||||
|
@@ -38,7 +38,7 @@ public:
|
||||
void setWaitingForAlbum();
|
||||
bool waitingForAlbum() const;
|
||||
|
||||
void forget();
|
||||
void unload();
|
||||
ImagePtr makeReplyPreview(Data::FileOrigin origin);
|
||||
|
||||
MTPInputPhoto mtpInput() const;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -420,8 +420,6 @@ public:
|
||||
const TextWithEntities &message,
|
||||
const MTPMessageMedia &media = MTP_messageMediaEmpty());
|
||||
|
||||
void forgetMedia();
|
||||
|
||||
void setMimeForwardIds(MessageIdsList &&list);
|
||||
MessageIdsList takeMimeForwardIds();
|
||||
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user