diff --git a/server/routes/detailedSearch.js b/server/routes/detailedSearch.js index e632b80..b016465 100644 --- a/server/routes/detailedSearch.js +++ b/server/routes/detailedSearch.js @@ -61,6 +61,7 @@ router.get("/", async (req, res) => { } else { clientData = null } + res.set("Cache-Control", "public, max-age=86400") res.json(clientData) } catch (err) { const msg = `An error occurred executing search search query. Message: ${err}` diff --git a/server/routes/generalDBSearch.js b/server/routes/generalDBSearch.js index 9009c89..9b75574 100644 --- a/server/routes/generalDBSearch.js +++ b/server/routes/generalDBSearch.js @@ -28,6 +28,7 @@ router.get("/", async (req, res) => { clientData = null break } + res.set("Cache-Control", "public, max-age=86400") res.json(clientData) } catch (err) { const msg = `An error occurred executing search search query. Message: ${err}` diff --git a/server/routes/geojsonSearch.js b/server/routes/geojsonSearch.js index 3a75221..6b60c0f 100644 --- a/server/routes/geojsonSearch.js +++ b/server/routes/geojsonSearch.js @@ -45,8 +45,11 @@ router.get("/", async (req, res) => { // check to see if there is a distance of 0 // which represents a target match - const { features } = pgData.data[0].jsonb_build_object - + const features = pgData.data.map((feature) => ({ + type: "Feature", + geometry: feature.geometry, + properties: feature, + })) // returns arrays const { targetAddress, nearbyAddresses } = findTargetAddress(features) @@ -137,7 +140,7 @@ router.get("/", async (req, res) => { year, }) - geoJSON = pgData.data[0].jsonb_build_object + geoJSON = { type: "FeatureCollection", features: pgData.data } clientData = checkEmptyGeoJSON(geoJSON) praxisDataType = "zipcode-intersect" break @@ -147,6 +150,7 @@ router.get("/", async (req, res) => { break } clientData.praxisDataType = praxisDataType + res.set("Cache-Control", "public, max-age=86400") res.json(clientData) } catch (err) { const msg = `An error occurred executing parcels geoJSON query. Message: ${err}` diff --git a/server/routes/primarySearch.js b/server/routes/primarySearch.js index e4eeb8c..0c86e67 100644 --- a/server/routes/primarySearch.js +++ b/server/routes/primarySearch.js @@ -34,6 +34,7 @@ router.get("/", async (req, res) => { clientData = null } + res.set("Cache-Control", "public, max-age=86400") res.json(clientData) } catch (err) { const msg = `An error occurred executing primary search query. Message: ${err}` diff --git a/server/utils/queries.js b/server/utils/queries.js index df0c5be..e3579ad 100644 --- a/server/utils/queries.js +++ b/server/utils/queries.js @@ -92,11 +92,7 @@ async function queryPGDB({ break case GEOJSON_ZIPCODES_PARCELS: - query = `SELECT jsonb_build_object( - 'type', 'FeatureCollection', - 'features', jsonb_agg(feature) - ) - FROM ( + query = ` SELECT jsonb_build_object( 'type', 'Feature', 'geometry', ST_AsGeoJSON(geometry, 6)::json, @@ -109,8 +105,7 @@ async function queryPGDB({ ON p.year = ${year} AND ST_Intersects(z.geometry, p.geom) ${createCodeSQLPredicate({ code, ownid, coordinates })} - ) inputs - ) features;` + ) inputs;` break case GEOJSON_PARCELS_CODE: @@ -197,59 +192,71 @@ async function queryPGDB({ /*currenlty dead query - not used*/ case GEOJSON_PARCELS_DISTANCE: - query = `SELECT jsonb_build_object( - 'type', 'FeatureCollection', - 'features', jsonb_agg(feature) - ) - FROM ( - SELECT jsonb_build_object( - 'type', 'Feature', - 'id', feature_id, - 'geometry', ST_AsGeoJSON(geom, 6)::json, - 'properties', to_jsonb(inputs) - 'geom', - 'centroid', ST_AsText(centroid) - ) AS feature - FROM ( - SELECT *, ST_Distance( - ST_SetSRID( - ST_MakePoint(${longitude}, ${latitude}), - 4326)::geography, - geom::geography) AS distance + query = ` + SELECT + feature_id, + saledate, + saleprice, + totsqft, + totacres, + cityrbuilt, + resyrbuilt, + prop_id, + year, + propaddr, + own_id, + taxpayer, + count, + own_group, + propno, + propdir, + propzip, + ST_AsText(centroid) AS centroid, + ST_AsGeoJSON(geom, 6)::json AS geometry, + ST_Distance( + ST_SetSRID( + ST_MakePoint(${longitude}, ${latitude}), + 4326)::geography, + geom::geography) AS distance FROM parcels WHERE year = ${year} AND ST_Distance( ST_SetSRID( ST_MakePoint(${longitude}, ${latitude}), 4326)::geography, - geom::geography) < ${searchRadius} - ) inputs - ) features;` + geom::geography) < ${searchRadius};` break case GEOJSON_PARCELS_CODE_DISTANCE: - query = `SELECT jsonb_build_object( - 'type', 'FeatureCollection', - 'features', jsonb_agg(feature) - ) - FROM ( - SELECT jsonb_build_object( - 'type', 'Feature', - 'id', feature_id, - 'geometry', ST_AsGeoJSON(geom, 6)::json, - 'properties', to_jsonb(inputs) - 'geom', - 'centroid', ST_AsText(centroid) - ) AS feature - FROM ( - SELECT *, ST_Distance( - ST_SetSRID( - ST_MakePoint(${longitude}, ${latitude}), - 4326)::geography, - geom::geography) AS distance + query = ` + SELECT + feature_id, + saledate, + saleprice, + totsqft, + totacres, + cityrbuilt, + resyrbuilt, + prop_id, + year, + propaddr, + own_id, + taxpayer, + count, + own_group, + propno, + propdir, + propzip, + ST_AsText(centroid) AS centroid, + ST_AsGeoJSON(geom, 6)::json AS geometry, + ST_Distance( + ST_SetSRID( + ST_MakePoint(${longitude}, ${latitude}), + 4326)::geography, + geom::geography) AS distance FROM parcels WHERE year = ${year} - AND propzip LIKE'${code}%' - ) inputs - ) features;` + AND propzip LIKE '${code}%';` break case POINT_CODE: diff --git a/tf/dev/main.tf b/tf/dev/main.tf index 2eb798f..82ac031 100644 --- a/tf/dev/main.tf +++ b/tf/dev/main.tf @@ -174,6 +174,7 @@ module "cloudfront" { # viewer_protocol_policy = "redirect-to-https" allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"] cached_methods = ["GET", "HEAD"] + compress = true query_string = true } ]