From 46c5deb58062416ae3562717e56758d3c21cce89 Mon Sep 17 00:00:00 2001 From: Martin Hilton Date: Wed, 13 Mar 2024 16:05:41 +0000 Subject: [PATCH] feat: limit the time period used in tag values queries Add a time interval limit when populating a tag values menu, this is to avoid the need to process the entire measurement. --- src/dataExplorer/context/tags.tsx | 3 ++- src/shared/constants/queryBuilder.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dataExplorer/context/tags.tsx b/src/dataExplorer/context/tags.tsx index 2b25ffce2a..a5ac7f1623 100644 --- a/src/dataExplorer/context/tags.tsx +++ b/src/dataExplorer/context/tags.tsx @@ -8,7 +8,7 @@ import { CACHING_REQUIRED_END_DATE, CACHING_REQUIRED_START_DATE, } from 'src/utils/datetime/constants' -import {DEFAULT_LIMIT} from 'src/shared/constants/queryBuilder' +import {DEFAULT_INTERVAL, DEFAULT_LIMIT} from 'src/shared/constants/queryBuilder' import {LanguageType} from 'src/dataExplorer/components/resources' // Contexts @@ -214,6 +214,7 @@ export const TagsProvider: FC = ({children, scope}) => { const queryTextSQL: string = ` SELECT DISTINCT("${tagKey}") FROM "${measurement}" + WHERE time < NOW() AND time >= NOW() - INTERVAL '${DEFAULT_INTERVAL}' ORDER BY "${tagKey}" LIMIT ${DEFAULT_LIMIT} ` diff --git a/src/shared/constants/queryBuilder.ts b/src/shared/constants/queryBuilder.ts index 8ad664f989..367ca7ce2d 100644 --- a/src/shared/constants/queryBuilder.ts +++ b/src/shared/constants/queryBuilder.ts @@ -1 +1,2 @@ export const DEFAULT_LIMIT = 1000 +export const DEFAULT_INTERVAL = '1 day'