Use cached views count from not modified page.

This commit is contained in:
John Preston 2024-07-02 10:40:39 +04:00
parent ad7d1fddf0
commit 3947056654
5 changed files with 22 additions and 5 deletions

View file

@ -71,6 +71,12 @@ bool Data::partial() const {
Data::~Data() = default;
void Data::updateCachedViews(int cachedViews) {
_source->updatedCachedViews = std::max(
_source->updatedCachedViews,
cachedViews);
}
void Data::prepare(const Options &options, Fn<void(Prepared)> done) const {
crl::async([source = *_source, options, done = std::move(done)] {
done(Prepare(source, options));

View file

@ -45,6 +45,8 @@ public:
[[nodiscard]] QString id() const;
[[nodiscard]] bool partial() const;
void updateCachedViews(int cachedViews);
void prepare(const Options &options, Fn<void(Prepared)> done) const;
private:

View file

@ -1001,14 +1001,20 @@ WebPageData *Instance::processReceivedPage(
owner->processChats(data.vchats());
auto &requested = _fullRequested[session][url];
const auto &mtp = data.vwebpage();
return mtp.match([&](const MTPDwebPageNotModified &data) {
return requested.page;
mtp.match([&](const MTPDwebPageNotModified &data) {
const auto page = requested.page;
if (const auto views = data.vcached_page_views()) {
if (page && page->iv) {
page->iv->updateCachedViews(views->v);
}
}
}, [&](const MTPDwebPage &data) {
requested.hash = data.vhash().v;
return owner->processWebpage(data).get();
requested.page = owner->processWebpage(data).get();
}, [&](const auto &) {
return owner->processWebpage(mtp).get();
requested.page = owner->processWebpage(mtp).get();
});
return requested.page;
}
void Instance::processOpenChannel(const QString &context) {

View file

@ -229,7 +229,9 @@ Parser::Parser(const Source &source, const Options &options)
_result.name = source.name;
_result.rtl = source.page.data().is_rtl();
const auto views = source.page.data().vviews().value_or_empty();
const auto views = std::max(
source.page.data().vviews().value_or_empty(),
source.updatedCachedViews);
const auto content = list(source.page.data().vblocks());
_result.content = wrap(content, views);
}

View file

@ -18,6 +18,7 @@ struct Source {
std::optional<MTPPhoto> webpagePhoto;
std::optional<MTPDocument> webpageDocument;
QString name;
int updatedCachedViews = 0;
};
[[nodiscard]] Prepared Prepare(const Source &source, const Options &options);