Repository navigation
fix(engine): annotations and report exports cover all of a layer read in place #1728
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
9d73072
b7dbe82
689036c
6534525
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 |
|---|---|---|
|
|
@@ -642,15 +642,46 @@ fn distance_range(s: &mut Session, p: &Value) -> CmdResult { | |
| }) | ||
| } | ||
|
|
||
| /// Whether layer `l` has text to convert into annotations at `scale`: a class's label field, or a | ||
| /// text expression. Decided on its fields, so before a layer read in place is read whole. | ||
| pub(crate) fn has_label_text(l: &rustgis_map::Layer, scale: f64) -> bool { | ||
| l.labels.in_order().any(|c| { | ||
| l.dataset.field_index(&c.field).is_some() | ||
| || rustgis_map::label_by::LabelExprs::new(&c.by, &l.dataset, Some(scale)).is_some_and(|e| e.has_text()) | ||
| }) | ||
| } | ||
|
|
||
| /// Converts a layer's labels into an annotation layer: one point per label, at the label point, | ||
| /// carrying the label text and drawn with the same text symbol. Each class labelling a feature | ||
| /// gives it a point (a hidden class none); with classes besides Default, a CLASS field keeps | ||
| /// which, and the annotation has the same classes, each picking its points by it. The layer's | ||
| /// own labels turn off. | ||
| /// own labels turn off. A layer read in place converts all of its source's features, not just | ||
| /// those of the view, and says the rows it couldn't read; it stays read in place. The app reads | ||
| /// them ahead on a thread of its own, as for Load All Features, whatever asks for the conversion | ||
| /// there; a script or the command line reads them where the command runs. The conversion itself | ||
| /// runs on the app's thread: it adds the annotation layer and turns the layer's labels off in one | ||
| /// undoable step, a pass over features already in memory. | ||
| fn convert(s: &mut Session, p: &Value) -> CmdResult { | ||
| let id = s.layer_id(p)?; | ||
| let scale = s.map().scale(); | ||
| let l = s.map().layer(id).ok_or("no such layer")?; | ||
| // Refused before a layer read in place is read whole for nothing. | ||
| if !has_label_text(s.map().layer(id).ok_or("no such layer")?, scale) { | ||
| return Err("the layer has no label field".into()); | ||
| } | ||
| // Its features, all of them: a copy of a layer read in place holds those of its whole source. | ||
| let whole = if s.map().layer(id).ok_or("no such layer")?.is_streamed() { | ||
| let (ds, unread) = super::whole::take_or_read(s, id)?; | ||
| let mut copy = s.map().layer(id).ok_or("no such layer")?.clone(); | ||
| copy.dataset = ds; | ||
| copy.source = None; | ||
|
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. AGENTS.md, Never hold the window (about 55% confidence). This read is new in this PR, and the conversion loop that follows (line 724, The doc comment's reason ("a pass over features already in memory") explains why the step must run on the app's thread, but not how long it can take. Options: build
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. The read, the part that grows with the source and touches files or the network, runs on a thread of its own in the app. The loop that follows is the same pass |
||
| Some((copy, unread)) | ||
| } else { | ||
| None | ||
| }; | ||
| let l = match &whole { | ||
| Some((copy, _)) => copy, | ||
| None => s.map().layer(id).ok_or("no such layer")?, | ||
| }; | ||
| let fields: Vec<Option<usize>> = l.labels.in_order().map(|c| l.dataset.field_index(&c.field)).collect(); | ||
| // Its classes' expressions, as the map draws them now (at its scale). | ||
| let exprs: Vec<Option<rustgis_map::label_by::LabelExprs>> = | ||
|
|
@@ -793,5 +824,8 @@ fn convert(s: &mut Session, p: &Value) -> CmdResult { | |
| if let Some(note) = cut_note { | ||
| s.notify(note, false); | ||
| } | ||
| if let Some((_, unread)) = &whole { | ||
| unread.say(s); | ||
| } | ||
| Ok(json!({"layer": new_id, "annotations": n})) | ||
| } | ||
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.
Bug (performance): a streamed layer's whole source is read before the command checks it has any labels to convert.
The whole read runs here (and, in the app, on the read-ahead thread from
reads.rs:102). The check at line 681 (the layer has no label field) comes after it. A layer with no label settings therefore reads its entire source, possibly a large PostGIS table, and then fails with that error. The read result is discarded.Failure scenario: a PostGIS layer read in place with no label field set. Clicking Convert starts a full background read, then reports "the layer has no label field".
Suggested fix: move the label-field check onto the live layer before
take_or_read, using the samefields/by_textlogic. Factor it into a helper, such ashas_label_field(l: &Layer), and call it inreads::prepareforlabels.convertbeforewhole::ahead, so no read is queued either. Add a test that a streamed layer with no labels fails without reading its source.Confidence: high (about 85%).
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.
Fixed in 6534525:
convertchecks first that the layer has label text (a class's label field or a text expression, decided on its fields byhas_label_text) and refuses before any whole read. The app's read-ahead (reads::prepare) checks the same and makes no read when there's nothing to convert.