Skip to content

Conversation

@nofurtherinformation
Copy link
Collaborator

@nofurtherinformation nofurtherinformation commented Sep 5, 2025

Currently, public views load in all the relevant data in the same way that the map editor does. This is generally fine, but leads to heavier database load for loading assignments (heavy for a complex plan) and client load for map data and demographic data.

This PR seeks to simplify this by using the recently implemented GET api/document/{document_id}/stats endpoint which generates a simple geojson with geoprocessing unioned districts and relevant stats.

Description

  • This PR turns off editing features and replaces them with a public layer that loads faster
  • Some slight tweaks will be needed to the demography service and choropleth mapping to ingest the new data
  • The geometry worker will also need tweaks

Reviewers

Checklist

  • Implement data fetching for public districts layer
  • Load data for demographic service and geometry worker from public districts layer
  • Adapt demography choropleth layer to be more generalized as a renderer
  • Load county filters from stats endpoint

Screenshots (if applicable):

@nofurtherinformation nofurtherinformation marked this pull request as ready for review September 15, 2025 14:06
const layerFilter = useLayerFilter(child);

const layerProps = useMemo(() => {
const overlayLayerProps: LayerProps = {
Copy link

Choose a reason for hiding this comment

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

The variable name overlayLayerProps is slightly confusing because it defines configuration for layers regardless of whether they are overlays or not, as we see with the use of isOverlay here.

What layer this actually represent? Is it more accurate to say polyLayerProps?

variant: demographicVariant,
mapRef: _map,
mapDocument,
numberOfBins: numberOfBins || 5,
Copy link

Choose a reason for hiding this comment

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

Should the default number of bins be stored as a constant and then imported here?

if (!ParquetWorker) {
throw new Error('ParquetWorker not found');
}
if (mapDocument.document_id === 'anonymous') {
Copy link

Choose a reason for hiding this comment

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

I see the anonymous document id referenced several times across the new and updated files. Perhaps it is worth making this a constant value as well?

const response = await get<Array<PublicDistrictData>>(`document/${mapDocument?.public_id}/stats`)(
{}
);
if (response.ok) {
Copy link

Choose a reason for hiding this comment

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

I noticed that HTTP request errors are swallowed here. Would it be worthwhile to bubble up the error instead so TanStack Query can attempt a retry in useMapBrowserEvents?

if (hash === this.hash) return;
this.availableColumns = columns;
this.table = table(data).derive(getColumnDerives(columns)).dedupe('path');
update(data: {columns: AllTabularColumns[number][]; results: ColumnarTableData}): void {
Copy link

Choose a reason for hiding this comment

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

The update method doc string is now out-of-date. More generally, if time permits, it would be nice to see more doc strings throughout the code base.

NOW() AS updated_at
FROM geos
{f"INNER JOIN gerrydb.{gerrydb_table} demo ON demo.path = geos.geo_id" if (gerrydb_table and demographic_json) else ""}
WHERE zone IS NOT NULL
Copy link

Choose a reason for hiding this comment

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

What does it mean to get rid of this clause? Was it redundant?


return (
<Source id={BLOCK_SOURCE_ID} type="geojson" data={getPublicMapData()} promoteId="zone">
{!isDemographicMap && (
Copy link

Choose a reason for hiding this comment

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

Perhaps a ternary expression would be cleaner here?

Copy link

@LaunaG LaunaG left a comment

Choose a reason for hiding this comment

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

Overall, this PR looks good to me, and the new functionality seems to work in the browser!

I only have a few minor questions and suggestions related to code clean-up and error handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants