Skip to content

Commit c9ecb4c

Browse files
authored
fix: add descending order to gtfs datasets endpoint (#1062)
1 parent 12b6511 commit c9ecb4c

File tree

8 files changed

+26
-17
lines changed

8 files changed

+26
-17
lines changed

api/src/feeds/impl/datasets_api_impl.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ class DatasetsApiImpl(BaseDatasetsApi):
2828

2929
@staticmethod
3030
def create_dataset_query() -> Query:
31-
return Query(
32-
[
33-
Gtfsdataset,
34-
Gtfsdataset.bounding_box.ST_AsGeoJSON(),
35-
Feed.stable_id,
36-
]
37-
).join(Feed, Feed.id == Gtfsdataset.feed_id)
31+
return (
32+
Query(
33+
[
34+
Gtfsdataset,
35+
Gtfsdataset.bounding_box.ST_AsGeoJSON(),
36+
Feed.stable_id,
37+
]
38+
)
39+
.join(Feed, Feed.id == Gtfsdataset.feed_id)
40+
.order_by(Gtfsdataset.downloaded_at.desc())
41+
)
3842

3943
@staticmethod
4044
def get_datasets_gtfs(query: Query, session: Session, limit: int = None, offset: int = None) -> List[GtfsDataset]:

api/tests/integration/test_feeds_api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ def test_get_gtfs_feed_datasets_with_limit(client: TestClient):
419419

420420
assert response.status_code == 200
421421
assert len(response.json()) == 1
422-
assert response.json()[0]["id"] == TEST_DATASET_STABLE_IDS[0]
422+
# the second dataset should be returned as it is the most recent
423+
assert response.json()[0]["id"] == TEST_DATASET_STABLE_IDS[1]
423424

424425

425426
def test_get_gtfs_feed_datasets_with_offset(client: TestClient):
@@ -434,7 +435,8 @@ def test_get_gtfs_feed_datasets_with_offset(client: TestClient):
434435

435436
assert response.status_code == 200
436437
assert len(response.json()) == 1
437-
assert response.json()[0]["id"] == TEST_DATASET_STABLE_IDS[1]
438+
# The first dataset should be returned as it is the oldest
439+
assert response.json()[0]["id"] == TEST_DATASET_STABLE_IDS[0]
438440

439441

440442
def test_get_gtfs_feed_datasets_with_downloaded_after_after(client: TestClient):
@@ -478,7 +480,7 @@ def test_get_gtfs_feed_datasets_with_downloaded_after_first(client: TestClient):
478480
Expected result: the full list of datasets
479481
"""
480482
datasets = get_all_datasets(client)
481-
datasets.pop(0)
483+
datasets.pop(len(datasets) - 1)
482484
date = datasets_download_first_date + timedelta(days=1)
483485
response = client.request(
484486
"GET",

docs/DatabaseCatalogAPI.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ paths:
178178
parameters:
179179
- $ref: "#/components/parameters/feed_id_of_datasets_path_param"
180180
get:
181-
description: Get a list of datasets related to a GTFS feed. Once a week, we check if the latest dataset has been updated and, if so, we update it in our system accordingly.
181+
description: Get a list of datasets associated with a GTFS feed. Once a day, we check whether the latest dataset has changed; if it has, we update it in our system. The list is sorted from newest to oldest.
182182
tags:
183183
- "feeds"
184184
operationId: getGtfsFeedDatasets

liquibase/changelog.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@
4343
<include file="changes/feat_966.sql" relativeToChangelogFile="true"/>
4444
<include file="changes/feat_946.sql" relativeToChangelogFile="true"/>
4545
<include file="changes/add_idxs.sql" relativeToChangelogFile="true"/>
46+
<include file="changes/feat_1046.sql" relativeToChangelogFile="true"/>
4647
</databaseChangeLog>

liquibase/changes/feat_1046.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Index to improve the filtering by feed_id and downloaded_at
2+
CREATE INDEX idx_gtfsdataset_feed_id_downloaded_at_desc ON GTFSDataset(feed_id, downloaded_at DESC);

web-app/public/locales/en/feeds.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
}
131131
},
132132
"datasetHistory": "Dataset History",
133-
"datasetHistoryDescription": "The Mobility Database fetches and stores new datasets twice a week, on Mondays and Thursdays at midnight EST.",
133+
"datasetHistoryDescription": "The Mobility Database fetches and stores new datasets once a day at midnight UTC.",
134134
"datasets": "Datasets",
135135
"validationReportNotAvailable": "Validation report not available",
136136
"runValidationReportYourself": "Run Validator Yourself",

web-app/src/app/screens/FAQ.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ export default function FAQ(): React.ReactElement {
174174
How often do you check for feed updates?
175175
</Typography>
176176
<Typography className='answer'>
177-
The Mobility Database checks for feed updates twice a week using the
178-
producer&apos;s URL, on Mondays and Thursdays. We store the new feed
179-
version if we detect a change.
177+
The Mobility Database checks for feed updates once a day at midnight
178+
UTC using the producer&apos;s URL. We store the new feed version if we
179+
detect a change.
180180
</Typography>
181181
</ColoredContainer>
182182
</Container>

web-app/src/app/services/feeds/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface paths {
4444
};
4545
};
4646
'/v1/gtfs_feeds/{id}/datasets': {
47-
/** @description Get a list of datasets related to a GTFS feed. Once a week, we check if the latest dataset has been updated and, if so, we update it in our system accordingly. */
47+
/** @description Get a list of datasets associated with a GTFS feed. Once a day, we check whether the latest dataset has changed; if it has, we update it in our system. The list is sorted from newest to oldest. */
4848
get: operations['getGtfsFeedDatasets'];
4949
parameters: {
5050
path: {
@@ -714,7 +714,7 @@ export interface operations {
714714
};
715715
};
716716
};
717-
/** @description Get a list of datasets related to a GTFS feed. Once a week, we check if the latest dataset has been updated and, if so, we update it in our system accordingly. */
717+
/** @description Get a list of datasets associated with a GTFS feed. Once a day, we check whether the latest dataset has changed; if it has, we update it in our system. The list is sorted from newest to oldest. */
718718
getGtfsFeedDatasets: {
719719
parameters: {
720720
query?: {

0 commit comments

Comments
 (0)