Skip to content

Architectural improvements: targeted rebuilds, single city source of truth, SQLite WAL + indexes, readiness() lock fix#7

Merged
fallofpheonix merged 3 commits into
mainfrom
copilot/audit-system-architecture-again
Mar 15, 2026
Merged

Architectural improvements: targeted rebuilds, single city source of truth, SQLite WAL + indexes, readiness() lock fix#7
fallofpheonix merged 3 commits into
mainfrom
copilot/audit-system-architecture-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 15, 2026

Full-stack audit addressing rebuild inefficiency in Flutter, duplicated data across layers, and SQLite performance bottlenecks in the Python backend.

Flutter — widget rebuild reduction

Before: HomeShell.build() was wrapped in AnimatedBuilder(animation: store), recreating all 4 page widget objects on every notifyListeners() call — forcing Flutter to diff and potentially re-render the entire IndexedStack subtree.

After: Pages created once in initState(); each screen subscribes to the store independently via ListenableBuilder:

// home_shell.dart — pages stable across store changes
@override
void initState() {
  super.initState();
  _pages = [
    MapScreen(store: widget.store),
    NewsScreen(store: widget.store),
    RouteScreen(store: widget.store),
    SourcesScreen(store: widget.store),
  ];
}

Per-screen subscription strategy:

  • _BlurAppBar, MapScreen, NewsScreen: full build() wrapped in ListenableBuilder
  • RouteScreen: only risk-result card wrapped — evaluate button (_isEvaluating) stays driven by setState
  • SourcesScreen: targeted wrappers on error message and source diagnostics; form fields unchanged

NewsScreen converted to StatefulWidget to cache DateFormat in initState() rather than re-instantiating on every build.

Flutter — single source of truth for city data

Removed two parallel city registries:

  • AppStore._supportedIndianCities — 27-entry Set<String>
  • _SourcesScreenState._indianCityCenters — 25-entry coordinate Map

Replaced by kCityCoordinates in models.dart, used for validation in AppStore.updateArea(), dropdown population, and coordinate auto-fill in SourcesScreen. Backward-compatible aliases ('New Delhi', 'Bangalore') included.

Python backend — SQLite performance

  • WAL mode: PRAGMA journal_mode=WAL in _init_schema() — concurrent reads no longer block on writes
  • Spatial indexes: (lat, lng) compound indexes on events_active, risk_cells, and events_log; city index on events_active — eliminates full table scans on the hot-path bounding-box BETWEEN queries
  • readiness() double lock: COUNT(*) FROM risk_cells was delegated to count_risk_cells(), acquiring self._lock a second time after readiness() had already released it. Query is now inlined within the existing lock block.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • sachet.ndma.gov.in
    • Triggering command: /usr/bin/python python -m pytest tests/ -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: fallofpheonix <160165035+fallofpheonix@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Flutter unit test suite to align GeoArea.center usage with the latlong2 LatLng type, consistent with the current GeoArea model.

Changes:

  • Update GeoArea test setup to use LatLng(...) directly instead of a removed/unused LatLngCoordinate(...).toLatLng() conversion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 168 to 172
test('produces correct query map keys', () {
final area = GeoArea(
city: 'Mumbai',
center: const LatLngCoordinate(19.076, 72.8777).toLatLng(),
center: LatLng(19.076, 72.8777),
radiusKm: 10,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes described in the PR title/description are now implemented in commit 924dbcd. That commit contains every item from the plan: single city source of truth (kCityCoordinates), targeted ListenableBuilder rebuild scoping across all screens, HomeShell page list stabilised in initState, DateFormat caching in NewsScreen, WAL mode, spatial indexes on events_active/risk_cells/events_log, and the readiness() double-lock fix. The PR description and title now accurately reflect the full changeset.

…ted widget rebuilds, SQLite WAL + indexes, readiness() lock fix

Co-authored-by: fallofpheonix <160165035+fallofpheonix@users.noreply.github.com>
Copilot AI changed the title [WIP] Run structured engineering audit on full-stack system Architectural improvements: targeted rebuilds, single city source of truth, SQLite WAL + indexes, readiness() lock fix Mar 15, 2026
Copilot AI requested a review from fallofpheonix March 15, 2026 09:30
@fallofpheonix
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

1 similar comment
@fallofpheonix
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

@fallofpheonix fallofpheonix marked this pull request as ready for review March 15, 2026 09:32
@fallofpheonix fallofpheonix merged commit 9fb7d40 into main Mar 15, 2026
6 of 7 checks passed
Copilot stopped work on behalf of fallofpheonix due to an error March 15, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants