Skip to content

Commit

Permalink
Limit latest_data to 7 days
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboucher committed Apr 24, 2022
1 parent d3c3ede commit 8f99774
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions packages/api/src/time-series/latest-data.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@ import { TimeSeries } from './time-series.entity';

@ViewEntity({
expression: (connection: Connection) => {
return (
connection
.createQueryBuilder()
.select(
'DISTINCT ON (metric, type, site_id, survey_point_id) time_series.id',
)
.addSelect('metric')
.addSelect('timestamp')
.addSelect('value')
.addSelect('type', 'source')
.addSelect('site_id')
.addSelect('survey_point_id')
.from(TimeSeries, 'time_series')
// TODO limit to 30 days to make it faster
.innerJoin('sources', 'sources', 'sources.id = time_series.source_id')
.orderBy('metric, type, site_id, survey_point_id, timestamp', 'DESC')
);
return connection
.createQueryBuilder()
.select(
'DISTINCT ON (metric, type, site_id, survey_point_id) time_series.id',
)
.addSelect('metric')
.addSelect('timestamp')
.addSelect('value')
.addSelect('type', 'source')
.addSelect('site_id')
.addSelect('survey_point_id')
.from(TimeSeries, 'time_series')
.where("timestamp > current_date - interval '7' day;")
.innerJoin('sources', 'sources', 'sources.id = time_series.source_id')
.orderBy('metric, type, site_id, survey_point_id, timestamp', 'DESC');
},
materialized: true,
})
Expand Down

0 comments on commit 8f99774

Please # to comment.