fix: honor date range in chat/topic export, skip pre-from history#30612
fix: honor date range in chat/topic export, skip pre-from history#30612Tym-arch wants to merge 1 commit into
Conversation
Approach A (GetHistory-based): probe-then-paginate skip-ahead via offset_date, till-stop in slice handler, applied to chat + topic paths. Closes telegramdesktop#30412, telegramdesktop#25139.
|
Two issues I hit while testing:
|
|
|
||
| 6.7.7 beta (20.04.26) | ||
|
|
||
| - Honor date range when exporting chat history (no full scan). |
There was a problem hiding this comment.
| - Honor date range when exporting chat history (no full scan). |
|
Hi everyone, just wanted to express my strong support for this PR. As someone who frequently exports chat data for analysis, the current behavior (scanning the entire history regardless of the selected time window) is a major bottleneck for large, long-standing chats. This optimization would be a massive quality-of-life improvement and save a lot of time. Thank you to the author for the great work on this! Is there anything the community can do to help get this reviewed and merged? |
Summary
Fixes the export-date-range bug reported in #30412 and #25139: selecting a date range in Export chat history causes the client to fetch the entire chat history from the oldest message before producing output. The date range is currently only applied at write time via
SkipMessageByDate, so on large channels (millions of msgs) the export appears stuck for hours and consumes massive bandwidth even when the user only wants a few days of msgs.This PR adds server-side skip-ahead so only msgs in the requested
[singlePeerFrom, singlePeerTill)range are ever transferred.Approach (canonical, GetHistory-based)
offsetDateparameter threaded throughrequestChatMessages→MTPmessages_GetHistory. All call sites updated. Default0preserves prior behavior.requestMessagesSlice: whenlargestIdPlusOne == 1andsinglePeerFrom > 0, fires a singlegetHistory(offset_id=0, offset_date=singlePeerFrom-1, add_offset=-1, limit=1)to find the first msg id at-or-aftersinglePeerFrom. SetslargestIdPlusOne = result.idand re-enters slice fetching from there. Mirrors the canonical pattern atapiwrap.cpp:3088(requestMessageAfterDate).slice.list.back().date >= singlePeerTill, setslastSlice = trueto terminate the split early instead of paginating to its end.SingleMessageAfter > date→>= dateinexport_data_types.cpp— splits whose latest msg date equalssinglePeerFromexactly were being skipped erroneously by the existing pre-iteration filter.requestTopicReplies/requestTopicMessagesSlice/finishTopicMessagesSlice(the date-range UI surfaces for topic exports too, perexport_view_settings.cpp:268-271).loadNextMessageFileSkipMessageByDate added so the file loader respects the date filter on topic msgs.onlyMyMessagesSearch fallback (kicked-from-channel mid-export) now passesmin_date = singlePeerFromandmax_date = (singlePeerTill > 0 ? singlePeerTill - 1 : 0)for correct inclusive-lower / exclusive-upper boundaries matchingSkipMessageByDate.Network savings
getHistoryper 100-msg batch across all msgs)~1000× reduction in request volume for the typical narrow-range case.
Backwards compatibility
offsetDateparameter defaults to0at every existing call site → unchanged behavior when no date range is set.onlyMyMessagesSearch, CHANNEL_PRIVATE fallback, migrated supergroup splits via negativesplitIndex) are preserved.Test plan
centos_envDocker image (CONFIG=Release, GCC 15) — clean build, 393 MB binary.Fixes #30412
Fixes #25139