Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fetch field_caps on TimeRange update spam #126

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading