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; 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 { void Data::prepare(const Options &options, Fn<void(Prepared)> done) const {
crl::async([source = *_source, options, done = std::move(done)] { crl::async([source = *_source, options, done = std::move(done)] {
done(Prepare(source, options)); done(Prepare(source, options));

View file

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

View file

@ -1001,14 +1001,20 @@ WebPageData *Instance::processReceivedPage(
owner->processChats(data.vchats()); owner->processChats(data.vchats());
auto &requested = _fullRequested[session][url]; auto &requested = _fullRequested[session][url];
const auto &mtp = data.vwebpage(); const auto &mtp = data.vwebpage();
return mtp.match([&](const MTPDwebPageNotModified &data) { mtp.match([&](const MTPDwebPageNotModified &data) {
return requested.page; 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) { }, [&](const MTPDwebPage &data) {
requested.hash = data.vhash().v; requested.hash = data.vhash().v;
return owner->processWebpage(data).get(); requested.page = owner->processWebpage(data).get();
}, [&](const auto &) { }, [&](const auto &) {
return owner->processWebpage(mtp).get(); requested.page = owner->processWebpage(mtp).get();
}); });
return requested.page;
} }
void Instance::processOpenChannel(const QString &context) { 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.name = source.name;
_result.rtl = source.page.data().is_rtl(); _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()); const auto content = list(source.page.data().vblocks());
_result.content = wrap(content, views); _result.content = wrap(content, views);
} }

View file

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