Skip to content

Commit

Permalink
Reduce initial load time for the browse page by only loading authorit…
Browse files Browse the repository at this point in the history
…y names, not full geojson
  • Loading branch information
dabreegster committed Aug 15, 2023
1 parent 0f5f879 commit eb642bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
6 changes: 6 additions & 0 deletions assets/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
Material Icons courtesy https://fonts.google.com/icons

`authority_names.json` is generated from `authorities.geojson` like this:

```
cat assets/authorities.geojson | jq '.features[].properties.name' | sort | jq -cs '.' > assets/authority_names.json
```
1 change: 1 addition & 0 deletions assets/authority_names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["Adur","Allerdale","Amber Valley","Arun","Ashfield","Ashford","Babergh","Barking and Dagenham","Barnet","Barnsley","Barrow-in-Furness","Basildon","Basingstoke and Deane","Bassetlaw","Bath and North East Somerset","Bedford","Bexley","Birmingham","Blaby","Blackburn with Darwen","Blackpool","Bolsover","Bolton","Boston","Bournemouth, Christchurch and Poole","Bracknell Forest","Bradford","Braintree","Breckland","Brent","Brentwood","Brighton and Hove","Bristol, City of","Broadland","Bromley","Bromsgrove","Broxbourne","Broxtowe","Buckinghamshire","Burnley","Bury","Calderdale","Cambridge","Cambridgeshire and Peterborough Combined Authority","Camden","Cannock Chase","Canterbury","Carlisle","Castle Point","Central Bedfordshire","Charnwood","Chelmsford","Cheltenham","Cherwell","Cheshire East","Cheshire West and Chester","Chesterfield","Chichester","Chorley","City of London","Colchester","Copeland","Cornwall","Cotswold","County Durham","Coventry","Craven","Crawley","Croydon","Cumbria","Dacorum","Darlington","Dartford","Derby","Derbyshire","Derbyshire Dales","Devon","Doncaster","Dorset","Dover","Dudley","Ealing","Eastbourne","East Cambridgeshire","East Devon","East Hampshire","East Hertfordshire","Eastleigh","East Lindsey","East Riding of Yorkshire","East Staffordshire","East Suffolk","East Sussex","Eden","Elmbridge","Enfield","Epping Forest","Epsom and Ewell","Erewash","Essex","Exeter","Fareham","Fenland","Folkestone and Hythe","Forest of Dean","Fylde","Gateshead","Gedling","Gloucester","Gloucestershire","Gosport","Gravesham","Greater London","Greater Manchester Combined Authority","Great Yarmouth","Greenwich","Guildford","Hackney","Halton","Hambleton","Hammersmith and Fulham","Hampshire","Harborough","Haringey","Harlow","Harrogate","Harrow","Hart","Hartlepool","Hastings","Havant","Havering","Herefordshire","Herefordshire, County of","Hertfordshire","Hertsmere","High Peak","Hillingdon","Hinckley and Bosworth","Horsham","Hounslow","Huntingdonshire","Hyndburn","Ipswich","Isle of Wight","Isles of Scilly","Islington","Kensington and Chelsea","Kent","King's Lynn and West Norfolk","Kingston upon Hull","Kingston upon Hull, City of","Kingston upon Thames","Kirklees","Knowsley","Lambeth","Lancashire","Lancaster","Leeds","Leicester","Leicestershire","Lewes","Lewisham","Lichfield","Lincoln","Lincolnshire","Liverpool","Liverpool City Region Combined Authority","Luton","Maidstone","Maldon","Malvern Hills","Manchester","Mansfield","Medway","Melton","Mendip","Merton","Mid Devon","Middlesbrough","Mid Suffolk","Mid Sussex","Milton Keynes","Mole Valley","Newark and Sherwood","Newcastle-under-Lyme","Newcastle upon Tyne","New Forest","Newham","Norfolk","North Devon","North East Derbyshire","North East Joint Transport Committee","North East Lincolnshire","North Hertfordshire","North Kesteven","North Lincolnshire","North Norfolk","North Northamptonshire","North Somerset","North Tyneside","Northumberland","North Warwickshire","North West Leicestershire","North Yorkshire","Norwich","Nottingham","Nottinghamshire","Nuneaton and Bedworth","Oadby and Wigston","Oldham","Oxford","Oxfordshire","Pendle","Peterborough","Plymouth","Portsmouth","Preston","Reading","Redbridge","Redcar and Cleveland","Redditch","Reigate and Banstead","Ribble Valley","Richmondshire","Richmond upon Thames","Rochdale","Rochford","Rossendale","Rother","Rotherham","Rugby","Runnymede","Rushcliffe","Rushmoor","Rutland","Ryedale","Salford","Sandwell","Scarborough","Sedgemoor","Sefton","Selby","Sevenoaks","Sheffield","Sheffield City Region Combined Authority","Shropshire","Slough","Solihull","Somerset","Somerset West and Taunton","Southampton","South Cambridgeshire","South Derbyshire","Southend-on-Sea","South Gloucestershire","South Hams","South Holland","South Kesteven","South Lakeland","South Norfolk","South Oxfordshire","South Ribble","South Somerset","South Staffordshire","South Tyneside","Southwark","Spelthorne","Stafford","Staffordshire","Staffordshire Moorlands","St Albans","Stevenage","St. Helens","Stockport","Stockton-on-Tees","Stoke-on-Trent","Stratford-on-Avon","Stroud","Suffolk","Sunderland","Surrey","Surrey Heath","Sutton","Swale","Swindon","Tameside","Tamworth","Tandridge","Tees Valley Combined Authority","Teignbridge","Telford and Wrekin","Tendring","Test Valley","Tewkesbury","Thanet","Three Rivers","Thurrock","Tonbridge and Malling","Torbay","Torridge","Tower Hamlets","Trafford","Tunbridge Wells","Uttlesford","Vale of White Horse","Wakefield","Walsall","Waltham Forest","Wandsworth","Warrington","Warwick","Warwickshire","Watford","Waverley","Wealden","Welwyn Hatfield","West Berkshire","West Devon","West Lancashire","West Lindsey","West Midlands ITA","Westminster","West Northamptonshire","West of England Combined Authority","West Oxfordshire","West Suffolk","West Sussex","West Yorkshire Combined Authority","Wigan","Wiltshire","Winchester","Windsor and Maidenhead","Wirral","Woking","Wokingham","Wolverhampton","Worcester","Worcestershire","Worthing","Wychavon","Wyre","Wyre Forest","York"]
25 changes: 10 additions & 15 deletions src/pages/BrowseSchemes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import "../style/main.css";
import type { MapGeoJSONFeature } from "maplibre-gl";
import { onDestroy, onMount } from "svelte";
import authorityNamesList from "../../assets/authority_names.json";
import BusRoutesLayerControl from "../lib/browse/BusRoutesLayerControl.svelte";
import CensusOutputAreaLayerControl from "../lib/browse/CensusOutputAreaLayerControl.svelte";
import CombinedAuthoritiesLayerControl from "../lib/browse/CombinedAuthoritiesLayerControl.svelte";
Expand All @@ -30,7 +31,6 @@
MapLibreMap,
ZoomOutMap,
} from "../lib/common";
import { getAuthoritiesGeoJson } from "../lib/common/data_getter";
import PmTiles from "../lib/common/PmTiles.svelte";
import InterventionLayer from "../lib/draw/InterventionLayer.svelte";
import { CheckboxGroup, ErrorMessage, SecondaryButton } from "../lib/govuk";
Expand All @@ -40,14 +40,11 @@
import type { Scheme as GjScheme } from "../types";
// TODO Remove after the input data is fixed to plumb correct authority names.
let authorityNames: Set<string> | null = null;
let authorityNames: Set<string> = new Set(authorityNamesList);
onMount(async () => {
onMount(() => {
// For govuk components. Must happen here.
initAll();
let geojson = await getAuthoritiesGeoJson();
authorityNames = new Set(geojson.features.map((f) => f.properties!.name));
});
const params = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -123,15 +120,13 @@
<Filters {schemes} bind:schemesToBeShown bind:filterText />
{/if}

{#if authorityNames}
<ul>
{#each schemes.values() as scheme}
{#if schemesToBeShown.has(scheme.scheme_reference)}
<SchemeCard {scheme} {authorityNames} />
{/if}
{/each}
</ul>
{/if}
<ul>
{#each schemes.values() as scheme}
{#if schemesToBeShown.has(scheme.scheme_reference)}
<SchemeCard {scheme} {authorityNames} />
{/if}
{/each}
</ul>
</div>
<div slot="main">
<PmTiles />
Expand Down

0 comments on commit eb642bd

Please sign in to comment.