mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 17:11:09 -05:00
3.7 KiB
3.7 KiB
Location App Analysis
1. PostGIS Features in Use
Spatial Fields
gis_models.PointField: TheLocationmodel inlocation/models.pyuses aPointFieldto store geographic coordinates.
GeoDjango QuerySet Methods
distance: Thedistance_tomethod in theLocationmodel calculates the distance between two points.distance_lte: Thenearby_locationsmethod uses thedistance_ltelookup to find locations within a certain distance.
Other GeoDjango Features
django.contrib.gis.geos.Point: ThePointobject is used to create point geometries from latitude and longitude.- PostGIS Backend: The project is configured to use the
django.contrib.gis.db.backends.postgisdatabase backend inthrillwiki/settings.py.
Spatial Indexes
- No explicit spatial indexes are defined in the
Locationmodel'sMetaclass.
2. Location-Related Views Analysis
Map Rendering
- There is no direct map rendering functionality in the provided views. The views focus on searching, creating, updating, and deleting location data, as well as reverse geocoding.
Spatial Calculations
- The
distance_toandnearby_locationsmethods in theLocationmodel perform spatial calculations, but these are not directly exposed as view actions. The views themselves do not perform spatial calculations.
GeoJSON Serialization
- There is no GeoJSON serialization in the views. The views return standard JSON responses.
3. Migration Strategy
Identified Risks
-
Data Loss Potential:
- Legacy latitude/longitude fields are synchronized with PostGIS point field
- Removing legacy fields could break synchronization logic
- Older entries might rely on legacy fields exclusively
-
Breaking Changes:
- Views depend on external Nominatim API rather than PostGIS
- Geocoding logic would need complete rewrite
- Address parsing differs between Nominatim and PostGIS
-
Performance Concerns:
- Missing spatial index on point field
- Could lead to performance degradation as dataset grows
Phased Migration Timeline
gantt
title Location System Migration Timeline
dateFormat YYYY-MM-DD
section Phase 1
Spatial Index Implementation :2025-08-16, 3d
PostGIS Geocoding Setup :2025-08-19, 5d
section Phase 2
Dual-system Operation :2025-08-24, 7d
Legacy Field Deprecation :2025-08-31, 3d
section Phase 3
API Migration :2025-09-03, 5d
Cache Strategy Update :2025-09-08, 2d
Backward Compatibility Strategy
- Maintain dual coordinate storage during transition
- Implement compatibility shim layer:
def get_coordinates(obj): return obj.point.coords if obj.point else (obj.latitude, obj.longitude) - Gradual migration of views to PostGIS functions
- Maintain legacy API endpoints during transition
Spatial Data Migration Plan
- Add spatial index to Location model:
class Meta: indexes = [ models.Index(fields=['content_type', 'object_id']), models.Index(fields=['city']), models.Index(fields=['country']), gis_models.GistIndex(fields=['point']) # Spatial index ] - Migrate to PostGIS geocoding functions:
- Use
ST_Geocodefor address searches - Use
ST_ReverseGeocodefor coordinate to address conversion
- Use
- Implement Django's
django.contrib.gis.gdalfor address parsing - Create data migration script to:
- Convert existing Nominatim data to PostGIS format
- Generate spatial indexes for existing data
- Update cache keys and invalidation strategy