feat: cache geojson data for vector files
This commit is contained in:
@@ -31,6 +31,7 @@ const datasetColumns = `id, category_id, name, description, unit, filename, stor
|
||||
CASE WHEN file_type = 'raster' AND geometry IS NOT NULL
|
||||
THEN ARRAY[ST_XMin(geometry), ST_YMin(geometry), ST_XMax(geometry), ST_YMax(geometry)]
|
||||
ELSE NULL END AS bbox,
|
||||
geojson,
|
||||
created_at, updated_at`
|
||||
|
||||
func scanDataset(row pgx.Row) (domain.Dataset, error) {
|
||||
@@ -40,7 +41,7 @@ func scanDataset(row pgx.Row) (domain.Dataset, error) {
|
||||
&d.Filename, &d.StorageKey, &d.CogStorageKey, &d.FileType, &d.SizeBytes, &d.ContentType,
|
||||
&d.Properties, &d.Meta, &d.Automated, &d.Status,
|
||||
&d.AttributeColumns, &d.KatoColumn, &d.YearColumns, &d.ParseError,
|
||||
&d.Geometry, &d.BBox, &d.CreatedAt, &d.UpdatedAt,
|
||||
&d.Geometry, &d.BBox, &d.GeoJSON, &d.CreatedAt, &d.UpdatedAt,
|
||||
)
|
||||
return d, err
|
||||
}
|
||||
@@ -193,6 +194,23 @@ func (r *DatasetRepository) MarkReady(ctx context.Context, id uuid.UUID, geometr
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetGeoJSON stores the pre-assembled GeoJSON FeatureCollection for a dataset
|
||||
// (nil -> NULL). It is written at processing time and served verbatim by the
|
||||
// .geojson endpoint.
|
||||
func (r *DatasetRepository) SetGeoJSON(ctx context.Context, id uuid.UUID, geojson []byte) error {
|
||||
tag, err := r.pool.Exec(ctx,
|
||||
`UPDATE datasets SET geojson = $2, updated_at = now() WHERE id = $1`,
|
||||
id, nullableJSON(json.RawMessage(geojson)),
|
||||
)
|
||||
if err != nil {
|
||||
return mapError(err)
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return domain.ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReplaceObservations atomically replaces all observations for a dataset.
|
||||
func (r *DatasetRepository) ReplaceObservations(ctx context.Context, datasetID uuid.UUID, obs []domain.Observation) error {
|
||||
tx, err := r.pool.Begin(ctx)
|
||||
|
||||
Reference in New Issue
Block a user