mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-28 00:02:12 +00:00
fix(send): charge the photo download window to the memory budget
A non-photo body charged the process-wide budget for as long as download_to_temp held it; a photo charged nothing until its prepare step, so the download itself — up to MAX_PHOTO_DOWNLOAD_BYTES per item, six items per batch, eight prep slots process-wide — was memory the MEMORY_BUDGET comment promised was bounded but was not (~6x32 MiB on top of the accounted512 MiB). Photos now reserve their own download cap for that window; the prepare step still charges header probe + decode buffer, the only overlap that is actually held in memory together. Net accounting stays within the declared budget instead of exceeding it whenever a batch of large photos downloads at once (audit: upload.rs photo window uncharged).
This commit is contained in:
@@ -112,16 +112,20 @@ async fn download_to_temp(
|
|||||||
} else {
|
} else {
|
||||||
MAX_MEDIA_UPLOAD_BYTES
|
MAX_MEDIA_UPLOAD_BYTES
|
||||||
};
|
};
|
||||||
// A non-photo body is buffered whole and can now be 50 MB, so it charges
|
// A non-photo body is buffered whole and charges the process-wide budget
|
||||||
// the process-wide budget for as long as this function holds it (one
|
// for as long as this function holds it (one 64 MiB unit covers the cap):
|
||||||
// 64 MiB unit covers the cap): `PREP_SLOTS` bounds how many are in flight,
|
// `PREP_SLOTS` bounds how many are in flight, this bounds what they add
|
||||||
// this bounds what they add up to. Photos charge their real buffer after
|
// up to. Photos charge their own download cap for the same window — their
|
||||||
// the download, once their header predicts it.
|
// real cost (header probe + decode buffer) is charged again by the
|
||||||
let _budget = if is_photo {
|
// prepare step right after, where both are actually held together.
|
||||||
None
|
let _budget = Some(
|
||||||
|
photo::reserve_memory(if is_photo {
|
||||||
|
photo::MAX_PHOTO_DOWNLOAD_BYTES
|
||||||
} else {
|
} else {
|
||||||
Some(photo::reserve_memory(MAX_MEDIA_UPLOAD_BYTES).await)
|
MAX_MEDIA_UPLOAD_BYTES
|
||||||
};
|
})
|
||||||
|
.await,
|
||||||
|
);
|
||||||
let bytes = match x_media::site::download_media_limited(
|
let bytes = match x_media::site::download_media_limited(
|
||||||
media_url,
|
media_url,
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
Reference in New Issue
Block a user