1+ import { get } from 'lodash' ;
12import {
23 chSqlToAliasMap ,
34 ClickHouseQueryError ,
@@ -127,14 +128,21 @@ export function useQueriedChartConfig(
127128 queryFn : streamedQuery ( {
128129 streamFn : context =>
129130 fetchDataInChunks ( config , clickhouseClient , context . signal ) ,
131+ /**
132+ * This mode ensures that data remains in the cache until the next full streamed result is available.
133+ * By default, the cache would be cleared before new data starts arriving, which results in the query briefly
134+ * going back into the loading/pending state when multiple observers are sharing the query result resulting
135+ * in flickering or render loops.
136+ */
137+ refetchMode : 'replace' ,
138+ initialValue : { data : [ ] , meta : [ ] , rows : 0 } as TQueryFnData ,
130139 reducer : ( acc , chunk ) => {
131140 return {
132141 data : [ ...( acc ?. data || [ ] ) , ...( chunk . data || [ ] ) ] ,
133142 meta : chunk . meta ,
134143 rows : ( acc ?. rows || 0 ) + ( chunk . rows || 0 ) ,
135144 } ;
136145 } ,
137- initialValue : { data : [ ] , meta : [ ] , rows : 0 } as TQueryFnData ,
138146 } ) ,
139147 retry : 1 ,
140148 refetchOnWindowFocus : false ,
@@ -144,23 +152,31 @@ export function useQueriedChartConfig(
144152 if ( query . isError && options ?. onError ) {
145153 options . onError ( query . error ) ;
146154 }
155+
156+ // const { isLoading, isSuccess, isPending, isError, isFetching, data } = query;
157+ // const queryKey = get(options, 'queryKey') ?? [config];
158+ // if (queryKey.length === 3) {
159+ // console.log('useQueriedChartConfig', {
160+ // queryKey: get(options, 'queryKey') ?? [config],
161+ // isLoading,
162+ // isSuccess,
163+ // isPending,
164+ // isError,
165+ // isFetching,
166+ // dataLength: data?.data?.length,
167+ // });
168+ // }
169+
147170 return query ;
148171}
149172
150173// TODO: Can we always search backwards or do we need to support forwards too?
151- // TODO: Check if this is impacted by timezones or DST changes
152- // TODO: What happens if date range is not provided? --> No pagination, or a default pagination?
153- // - In the sidebar onboarding checklist component
154- // - where else?
174+ // TODO: Check if this is impacted by timezones or DST changes --> Everything UTC? Should be fine.
155175// TODO: See if we can combine this with the useOffsetPaginatedQuery stuff
156176// TODO: How does live mode affect this?
157177// TODO: Can we remove the IS_MTVIEWS_ENABLED stuff?
158178// TODO: How is caching working?
159- // TODO: Granularity not provided --> use any default, or is this every automatically added?
160- // - In the patterns table
161- // - where else?
162- // TODO: What if we group by something that isn't a date?
163- // - Probably OK if we are also grouping by time, but not OK if we aren't also grouping by time?
179+ // Test that this works as expected with no pagination in place (eg. no granularity or no date range)
164180
165181export function useRenderedSqlChartConfig (
166182 config : ChartConfigWithOptDateRange ,
0 commit comments