Repository navigation
feat(engine): a linked layer says when its source's feature count has changed #3272
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
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -119,6 +119,7 @@ impl AmbiguousAreas { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// A streamed layer's source. | ||||||||||||||||||||||
| #[derive(Clone, Default, Serialize, Deserialize)] | ||||||||||||||||||||||
| #[serde(remote = "Self")] | ||||||||||||||||||||||
|
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.
Category: quality |
||||||||||||||||||||||
| pub struct SourceLayer { | ||||||||||||||||||||||
| /// The file it reads; reopened when the project loads. | ||||||||||||||||||||||
| #[serde(default)] | ||||||||||||||||||||||
|
|
@@ -129,6 +130,12 @@ pub struct SourceLayer { | |||||||||||||||||||||
| /// The GeoPackage table. | ||||||||||||||||||||||
| #[serde(default)] | ||||||||||||||||||||||
| pub table: Option<String>, | ||||||||||||||||||||||
| /// The whole-source count saved with this layer, until the reopened header is compared. | ||||||||||||||||||||||
| #[serde(default, skip_serializing_if = "Option::is_none", getter = "Self::feature_count_for_save")] | ||||||||||||||||||||||
| saved_feature_count: Option<u64>, | ||||||||||||||||||||||
| /// The whole-source count seen at the first source header check. | ||||||||||||||||||||||
| #[serde(skip)] | ||||||||||||||||||||||
| checked_feature_count: Option<u64>, | ||||||||||||||||||||||
| /// A Shapefile's source CRS override, reapplied when its path is reopened. | ||||||||||||||||||||||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||||||||||||||||||||||
| pub shapefile_crs: Option<rustgis_data::raster::Crs>, | ||||||||||||||||||||||
|
|
@@ -273,6 +280,18 @@ pub struct SourceLayer { | |||||||||||||||||||||
| pub sqlserver: Option<SqlServerOrigin>, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| impl Serialize for SourceLayer { | ||||||||||||||||||||||
| fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||||||||||||||||||||||
| Self::serialize(self, serializer) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| impl<'de> Deserialize<'de> for SourceLayer { | ||||||||||||||||||||||
| fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||||||||||||||||||||||
| Self::deserialize(deserializer) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// A PostGIS table a layer reads live. | ||||||||||||||||||||||
| #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||||||||||||||||||||||
| pub struct PostgisOrigin { | ||||||||||||||||||||||
|
|
@@ -882,6 +901,8 @@ impl SourceLayer { | |||||||||||||||||||||
| path: _, | ||||||||||||||||||||||
| file_name: _, | ||||||||||||||||||||||
| table: _, | ||||||||||||||||||||||
| saved_feature_count: _, | ||||||||||||||||||||||
| checked_feature_count: _, | ||||||||||||||||||||||
| shapefile_crs, | ||||||||||||||||||||||
| embedded: _, | ||||||||||||||||||||||
| handle: _, | ||||||||||||||||||||||
|
|
@@ -1073,7 +1094,44 @@ impl SourceLayer { | |||||||||||||||||||||
| if self.same_opening(live) { | ||||||||||||||||||||||
| self.read_notes.clone_from(&live.read_notes); | ||||||||||||||||||||||
| self.read_note_kinds.clone_from(&live.read_note_kinds); | ||||||||||||||||||||||
| self.saved_feature_count = live.saved_feature_count; | ||||||||||||||||||||||
| self.checked_feature_count = live.checked_feature_count; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// A direct file link's known whole-source count. Opening may have omitted unreadable rows | ||||||||||||||||||||||
| /// from that metadata. Conversions can contain a geometry subset, and live table counts can | ||||||||||||||||||||||
| /// be filtered or estimated. | ||||||||||||||||||||||
| fn linked_feature_count(&self) -> Option<u64> { | ||||||||||||||||||||||
| let linked = self.linked_file().is_some() || self.path.as_deref().is_some_and(rustgis_data::source::is_remote_name); | ||||||||||||||||||||||
| if self.gdal.is_some() || self.duckdb.is_some() || !linked { | ||||||||||||||||||||||
| return None; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| let handle = self.handle.as_ref()?; | ||||||||||||||||||||||
| if handle.skipped_at_open() > 0 { | ||||||||||||||||||||||
| return None; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| handle.info().count | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// The count this source will write, obtained without opening the source or reading rows. | ||||||||||||||||||||||
| /// Unopened links retain the last known count. | ||||||||||||||||||||||
| pub fn feature_count_for_save(&self) -> Option<u64> { | ||||||||||||||||||||||
| if self.is_open() { self.linked_feature_count() } else { self.checked_feature_count.or(self.saved_feature_count) } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+1119
to
+1121
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 a source is open, this returns the live header count and ignores the saved baseline. The baseline is only compared at
A save of a project that was just opened, with no frame between, does the same. Keeping an uncompared or unsaid baseline until it is taken fixes all three. Please also add a regression test that saves before any view sync and one that imports a linked layer, since the current test only saves after a sync.
Suggested change
Category: bug |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Records the first comparable header, independently of which rows the view asks for. | ||||||||||||||||||||||
| pub fn check_feature_count(&mut self) { | ||||||||||||||||||||||
| if self.saved_feature_count.is_some() && self.checked_feature_count.is_none() { | ||||||||||||||||||||||
| self.checked_feature_count = self.linked_feature_count(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Takes the saved-to-current difference once, including across subsequent view reads. | ||||||||||||||||||||||
| pub fn take_feature_count_change(&mut self) -> Option<(u64, u64)> { | ||||||||||||||||||||||
| let current = self.checked_feature_count?; | ||||||||||||||||||||||
| let saved = self.saved_feature_count.take()?; | ||||||||||||||||||||||
| (saved != current).then_some((saved, current)) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Whether another installed window needs its retained display expressions checked. | ||||||||||||||||||||||
|
|
@@ -2371,6 +2429,8 @@ impl SourceLayer { | |||||||||||||||||||||
| path, | ||||||||||||||||||||||
| file_name: _, | ||||||||||||||||||||||
| table: _, | ||||||||||||||||||||||
| saved_feature_count: _, | ||||||||||||||||||||||
| checked_feature_count: _, | ||||||||||||||||||||||
| shapefile_crs: _, | ||||||||||||||||||||||
| embedded, | ||||||||||||||||||||||
| handle: _, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"format":2,"name":"Linked source count","maps":[{"name":"Map","layers":[{"id":1,"name":"Parcels","visible":true,"dataset":{"name":"Parcels","geometry_type":"Point","fields":[{"name":"rank","ty":"Integer","alias":null}],"features":[],"source":"./points.geojson"},"renderer":{"Single":{"fill":[224,123,57,255],"stroke":[255,255,255,255],"stroke_width":1.0,"size":7.0,"marker":"Circle"}},"labels":{"enabled":false,"field":"rank","size":10.0,"color":[43,43,43,255],"halo":true,"bold":false,"min_scale":null,"max_scale":null,"closest":null,"farthest":null,"placement":"Auto"},"transparency":0.0,"min_scale":null,"max_scale":null,"definition_query":null,"selection":[],"expanded":true,"selectable":true,"graphics":false,"blend":"Normal","mask":null,"display_filters":[],"aggregation":null,"extrusion":null,"priority":0,"source":{"path":"./points.geojson","file_name":null,"table":null,"saved_feature_count":2},"geometry_rev":0}],"basemap":"Paper","camera":{"center":{"x":0.0,"y":167006.2942262065},"res":173.22577333514909,"bearing":0.0,"pitch":0.0},"bookmarks":[],"graticule":true,"projection":"WebMercator","popup_mode":"Topmost","label_display":{"paused":false,"locked":false,"show_unplaced":false},"editing":{"relationships":[],"snapping":{"enabled":false,"tolerance_px":10.0,"vertex":true,"edge":true,"end":true},"topology":[],"settings":{"enabled":true,"show_vertices":true,"elevation":"None","ground_to_grid":null}},"swipe":null,"view":{"effects":{"stars":true,"sun_time":null,"weather":"None","vignette":false,"edges":false,"tilt_shift":false,"grain":false,"brightness":0.0,"contrast":0.0,"saturation":0.0,"sepia":0.0},"wireframe":false,"clip_distance":null,"terrain":null},"animation":[],"next_layer_id":2}],"active_map":0,"tables":[],"next_table_id":1,"gp_history":[],"layouts":[],"folders":[],"styles":[],"ramps":[],"tasks":[],"gp_env":{"extent":null,"cell_size":null},"models":[],"workspaces":[],"link_views":false,"jobs":[],"offline_areas":[],"reports":[],"presentations":[],"notebooks":[],"dl_models":[],"shared":[],"data_stores":[],"requires":["linked-source-feature-count"]} |
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.
AGENTS.md asks for one notice per kind with a count. This pushes one notice per linked layer, so a project with several changed links gives several notices of the same kind. The existing
source_errorspath already aggregates this way, with a count. The same pattern would fit here: collect(name, saved, current)and emit onesource_count_changed-style notice with a count, or name the layers in a list. The test that checks one notice per layer would then need updating.Category: agents-md