Repository navigation
fix(ui): hold the web app's save, share and export buttons to the download limit #3311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a5463c3
d46727d
dbbb928
bedcaae
344499c
a91af92
3ba19ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1921,9 +1921,12 @@ pub fn item_bytes(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Vec | |
| Ok((name, bytes)) | ||
| } | ||
|
|
||
| /// Builds an item and returns construction-loss notes for publication only after delivery. | ||
| /// Builds an item and returns construction-loss notes for publication only after delivery. In the | ||
| /// browser, where it is downloaded, it is stopped as it passes the room a download has. | ||
| pub fn item_output(s: &mut Session, kind: &str, p: &Value) -> Result<(String, Vec<u8>, rustgis_data::loss::Notes), String> { | ||
| item_output_within(s, kind, p, Output::UNLIMITED) | ||
| let what = ITEMS.iter().find(|i| i.0 == kind).map_or("the file", |i| i.2); | ||
| let out = Output::here(s, what)?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, grouped with the other small points. The refusal reads Two smaller points, same group. The Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All three are in the next push: the comment says what the label is, |
||
| item_output_within(s, kind, p, out) | ||
| } | ||
|
|
||
| /// [`item_output`] for the file `out` describes: a downloaded one is stopped as it passes its room. | ||
|
|
@@ -2006,7 +2009,7 @@ fn item_output_within( | |
| } | ||
| "projectPackage" => (s.project.name.clone(), package_project(s, &mut construction_notes, out)?), | ||
| "fieldPackage" => { | ||
| let (name, bytes, notes) = super::field::package_output(s, p)?; | ||
| let (name, bytes, notes) = super::field::package_output_within(s, p, out)?; | ||
| construction_notes.extend(notes); | ||
| (name, bytes) | ||
| } | ||
|
|
@@ -2072,6 +2075,8 @@ fn item_output_within( | |
| } | ||
| k => return Err(format!("unknown item '{k}'")), | ||
| }; | ||
| // A small file's writer, such as the bookmarks', takes no limit. | ||
| out.check(bytes.len())?; | ||
| let ext = ITEMS.iter().find(|i| i.0 == kind).map_or("json", |i| i.1); | ||
| Ok((format!("{}.{ext}", safe(&name)), bytes, construction_notes)) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -943,6 +943,9 @@ pub struct Session { | |
| notices_given: u64, | ||
| /// While a download's file is made, the notices that wait with it ([`Session::holding_notices`]). | ||
| held_notices: Option<Vec<Notice>>, | ||
| /// While the front end runs a command whose file it downloads, the most bytes it takes | ||
| /// ([`Session::offer_files`]). | ||
| offering: Option<usize>, | ||
| /// Loss notices given in this session by code, including ones no longer kept, less those a | ||
| /// failed command withdrew (see [`Session::losses_given`]). | ||
| losses_given: Vec<(rustgis_data::loss::LossCode, u64)>, | ||
|
|
@@ -1538,6 +1541,7 @@ impl Session { | |
| diagnostics: rustgis_data::diagnostics::History::default(), | ||
| notices_given: 0, | ||
| held_notices: None, | ||
| offering: None, | ||
| losses_given: Vec::new(), | ||
| beyond_said: None, | ||
| crs_notes_said: Vec::new(), | ||
|
|
@@ -1854,7 +1858,20 @@ impl Session { | |
| if self.queue_gp_files { | ||
| return true; | ||
| } | ||
| cfg!(target_arch = "wasm32") | ||
| self.offering.is_some() || cfg!(target_arch = "wasm32") | ||
| } | ||
|
|
||
| /// For a front end whose button saves by downloading: until it is set back, a command that | ||
| /// takes a path queues its file ([`Session::take_gp_files`]) as a browser's script does, held | ||
| /// to `most` bytes ([`cmd::exports::NO_DOWNLOAD_LIMIT`] for no limit but memory). It leaves saying that the file was | ||
| /// offered to the front end. Gives what was set before. | ||
| pub fn offer_files(&mut self, most: Option<usize>) -> Option<usize> { | ||
| std::mem::replace(&mut self.offering, most) | ||
| } | ||
|
|
||
| /// Whether the front end says itself that a file was offered ([`Session::offer_files`]). | ||
| pub(crate) fn offers_files(&self) -> bool { | ||
| self.offering.is_some() | ||
| } | ||
|
|
||
| /// The most bytes the files waiting for download may hold in all. | ||
|
|
@@ -1863,7 +1880,7 @@ impl Session { | |
| if let Some(cap) = self.download_cap { | ||
| return cap; | ||
| } | ||
| cmd::exports::MAX_DOWNLOAD_BYTES | ||
| self.offering.unwrap_or(cmd::exports::MAX_DOWNLOAD_BYTES) | ||
| } | ||
|
|
||
| /// Where files are downloaded, the room for one more; `None` where they are written. Refused | ||
|
|
@@ -1873,7 +1890,9 @@ impl Session { | |
| return Ok(None); | ||
| } | ||
| let waiting = self.waiting_download_bytes(); | ||
| let bytes = self.download_cap().saturating_sub(waiting); | ||
| // No limit stays none whatever waits. | ||
| let cap = self.download_cap(); | ||
| let bytes = if cap == cmd::exports::NO_DOWNLOAD_LIMIT { cap } else { cap.saturating_sub(waiting) }; | ||
| if self.waiting_download_count() >= cmd::exports::MAX_DOWNLOADS || bytes == 0 { | ||
| return Err(cmd::gp::queue_full(self.download_cap())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there is no byte limit (the phone, where Category: quality
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, and the count is the limit that trips there. Left for the release quality pass: it needs eight files that were never acknowledged, which a button never leaves. |
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the read for
share.exportLayeranddata.convert, but its sibling incrates/engine/src/cmd/sharing.rs:383(load_whole) doesn't get the same fix. It callsread_for_download_after(l, *held)wheneverout.downloads()is true. On the phone the room isNO_DOWNLOAD_LIMIT, sodownloads()is still true and the read stops at 256 MiB of features.load_wholeis reached from the web map, web layer, geodata service and web scene items (webMap,webLayer,geodataService,webScene) throughitem_outputanddownload_share, so the phone's buttons for those now refuse a large streamed layer. Before this PR the phone read them whole. That contradicts the description's "no limit, as before".Suggested fix, in
load_wholeinsharing.rs: take the bounded read only when there is a limit, so both readers agree:let (ds, unread) = if out.downloads() && out.most() != super::exports::NO_DOWNLOAD_LIMIT { super::exports::read_for_download_after(l, *held)? } else { l.load_all_counted()? };The new tests don't reach this.
a_button_over_the_download_limit_offers_nothinguses small fixtures, and the item test runs only with the 10-byte cap. A streamed layer checked underoffer_most = Some(usize::MAX)would catch it.Category: bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phone does not reach this. Its share buttons run
ui.saveItem, which callsitem_outputwithoutoffer_files, soOutput::herefinds no downloads (downloads_filesis false off the browser),out.downloads()is false and the layer is read whole, as before.run_offering, the only caller ofoffer_files, runs no share command. The two readers should agree all the same, so a caller added later cannot meet it: that comes with the next pull request for #3153.