Skip to content

Commit

Permalink
Merge pull request #126 from quickwit-oss/ddelemeny/fix-fieldcaps-spam
Browse files Browse the repository at this point in the history
Don't fetch field_caps on TimeRange update spam
  • Loading branch information
ddelemeny authored May 9, 2024
2 parents 604983d + 041f5c5 commit ad87ff5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/datasource/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ export type Suggestion = {
export function useDatasourceFields(datasource: BaseQuickwitDataSource, range: TimeRange) {
const [fields, setFields] = useState<MetricFindValue[]>([]);

const [niceRange, setNiceRange] = useState(()=>range)

useEffect(() => {
// range may change several times during a render with a delta of a few hundred milliseconds
// we don't need to fetch with such a granularity, this effect filters out range updates that are within the same minute
if (range.from.isSame(niceRange.from, 'minute') && range.to.isSame(niceRange.to, 'minute')) { return }
setNiceRange(range)
},[range, niceRange])

useEffect(() => {
if (datasource.getTagKeys) {
datasource.getTagKeys({ searchable: true, timeRange: range}).then(setFields);
datasource.getTagKeys({ searchable: true, timeRange: niceRange}).then(setFields);
}
}, [datasource, range, setFields]);
}, [datasource, niceRange])

const getSuggestions = useCallback(async (word: string): Promise<Suggestion> => {
let suggestions: Suggestion = { from: 0, options: [] };
Expand Down

0 comments on commit ad87ff5

Please sign in to comment.