Skip to content

Commit f1a87fe

Browse files
committed
refactor(backend/api): remove duplicate cache control header and ensure consistent read for job updates
1 parent 5509bd4 commit f1a87fe

3 files changed

Lines changed: 6 additions & 11 deletions

File tree

backend/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ Or mount `~/.aws` when using Docker (already configured in docker-compose.yml).
267267

268268
The API implements strict caching controls to ensure UI consistency:
269269

270-
- **GET /jobs/{id}**: `Cache-Control: private, max-age=0, must-revalidate`. Forces browsers to validate ETag on every request, ensuring deployment status changes are seen immediately.
270+
- **GET /jobs/{id}**: `Cache-Control: private, max-age=0, must-revalidate`. Forces browsers to validate ETag on every request, ensuring deployment status changes are seen immediately. Uses DynamoDB Strong Consistency (`ConsistentRead=True`) to generate accurate ETags.
271271
- **DELETE /jobs/{id}**: Returns `Cache-Control: no-store, no-cache, must-revalidate, max-age=0` to immediately invalidate client caches.
272-
- **Consistency**: Critical endpoints (`update_job_metadata`, `deploy_model`) use DynamoDB Strong Consistency (`ConsistentRead=True`) to guarantee read-after-write accuracy.
272+
- **Consistency**: Critical operations (`update_job_metadata`, `deploy_model`) use DynamoDB Strong Consistency (`ConsistentRead=True`) to guarantee read-after-write accuracy.
273273

274274
## 🧪 Testing
275275

@@ -280,14 +280,14 @@ The backend includes comprehensive unit and integration tests for both API and T
280280
```
281281
backend/tests/
282282
├── pytest.ini # Pytest configuration
283-
├── api/ # API tests (104 tests, 69% coverage)
283+
├── api/ # API tests (109 tests, 71% coverage)
284284
│ ├── conftest.py # Shared fixtures
285285
│ ├── test_endpoints.py # Endpoint tests (39 tests)
286286
│ ├── test_schemas.py # Pydantic validation tests (23 tests)
287287
│ ├── test_dynamo_service.py # DynamoDB service tests
288288
│ ├── test_s3_service.py # S3 service tests
289289
│ └── test_services_integration.py # moto-based integration tests (21 tests)
290-
└── training/ # Training tests (159 tests, 53% coverage)
290+
└── training/ # Training tests (159 tests, 63% coverage)
291291
├── conftest.py # Shared fixtures
292292
├── unit/ # Pure unit tests
293293
│ ├── test_preprocessor.py

backend/api/routers/models.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ async def delete_job(job_id: str, response: Response, delete_data: bool = True)
220220
# Ensure client caches are invalidated immediately
221221
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
222222

223-
# Ensure client caches are invalidated immediately
224-
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
225-
226223
return {
227224
"message": "Job deleted successfully",
228225
"job_id": job_id,
@@ -247,7 +244,8 @@ async def update_job_metadata(job_id: str, update_request: JobUpdateRequest, res
247244
"""
248245
try:
249246
# Verify job exists
250-
job = dynamodb_service.get_job(job_id)
247+
# Use consistent read to ensure we have the absolute latest state before validating and updating
248+
job = dynamodb_service.get_job(job_id, consistent_read=True)
251249
if not job:
252250
raise HTTPException(
253251
status_code=status.HTTP_404_NOT_FOUND,

backend/api/services/s3_service.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ def generate_presigned_download_url_cached(
118118
logger.info(f"Cached presigned URL for s3://{bucket}/{key} (TTL: {cache_ttl}s)")
119119
return url
120120

121-
logger.info(f"Cached presigned URL for s3://{bucket}/{key} (TTL: {cache_ttl}s)")
122-
return url
123-
124121
def check_object_exists(self, bucket: str, key: str) -> bool:
125122
"""Check if an object exists in S3"""
126123
try:

0 commit comments

Comments
 (0)