Skip to content

Commit

Permalink
fix(lib): query_cache_system_table_handling=save for system table
Browse files Browse the repository at this point in the history
  • Loading branch information
duyet committed Jun 30, 2024
1 parent d3cb8aa commit e17e756
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion components/menu/count-badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export async function CountBadge({
const { data } = await fetchData<{ 'count()': string }[]>({
query: sql,
format: 'JSONEachRow',
clickhouse_settings: { use_query_cache: 1, query_cache_ttl: 120 },
clickhouse_settings: {
use_query_cache: 1,
query_cache_system_table_handling: 'save',
query_cache_ttl: 120,
},
})

if (!data || !data.length || !data?.[0]?.['count()']) return null
Expand Down
7 changes: 6 additions & 1 deletion lib/clickhouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { cache } from 'react'

const DEFAULT_CLICKHOUSE_MAX_EXECUTION_TIME = '60'

type QuerySettings = QueryParams['clickhouse_settings'] & {
// @since 24.4
query_cache_system_table_handling: 'throw' | 'save' | 'ignore'
}

export const getClickHouseHosts = () => {
const hosts = (process.env.CLICKHOUSE_HOST || '')
.split(',')
Expand Down Expand Up @@ -54,7 +59,7 @@ export const fetchData = async <
query_params,
format = 'JSONEachRow',
clickhouse_settings,
}: QueryParams): Promise<{
}: QueryParams & { clickhouse_settings: QuerySettings }): Promise<{
data: T
metadata: Record<string, string | number>
}> => {
Expand Down

0 comments on commit e17e756

Please sign in to comment.