Skip to content

Commit baa8692

Browse files
committed
solution to exclude changesets newer than 5 minutes from the api results
1 parent fd093c4 commit baa8692

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "osmcha-frontend",
3-
"version": "0.58.1",
3+
"version": "0.58.2",
44
"license": "ISC",
55
"engines": {
66
"node": ">=7.0"

src/config/constants.js

+5
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ export const whosThat =
1919

2020
export const nominatimUrl = 'https://nominatim.openstreetmap.org/search.php';
2121

22+
// set a default from date x days before today
2223
export const DEFAULT_FROM_DATE = 7;
24+
// exclude changesets newer than x minutes. It's needed because of the difference
25+
// between the time a changeset is processed by OSMCha and the time its map
26+
// visualization is available
27+
export const DEFAULT_TO_DATE = 5;

src/utils/filters.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { List, Map, fromJS } from 'immutable';
33
import moment from 'moment';
44

5-
import { DEFAULT_FROM_DATE } from '../config/constants';
5+
import { DEFAULT_FROM_DATE, DEFAULT_TO_DATE } from '../config/constants';
66
import type { filtersType } from '../components/filters';
77

88
export function validateFilters(filters: filtersType): boolean {
@@ -47,9 +47,27 @@ export function getDefaultFromDate(): filtersType {
4747
});
4848
}
4949

50+
export function getDefaultToDate(): filtersType {
51+
const defaultDate = moment()
52+
.subtract(DEFAULT_TO_DATE, 'minutes')
53+
.utc()
54+
.format('YYYY-MM-DD HH:mm');
55+
return fromJS({
56+
date__lte: [
57+
{
58+
label: '',
59+
value: defaultDate
60+
}
61+
]
62+
});
63+
}
64+
5065
export function appendDefaultDate(filters: filtersType) {
5166
if (filters && !filters.has('date__gte') && !filters.has('date__lte')) {
5267
filters = filters.merge(getDefaultFromDate());
5368
}
69+
if (filters && !filters.has('date__lte')) {
70+
filters = filters.merge(getDefaultToDate());
71+
}
5472
return filters;
5573
}

0 commit comments

Comments
 (0)