From 70917b97061953817ae62c77e80942f0b8b23b79 Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Mon, 28 Oct 2024 14:03:05 +0100 Subject: [PATCH] perf(max): Use `async_except_on_cache_miss` in question suggestions (#25803) Co-authored-by: Georgiy Tarasov Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- frontend/src/lib/api.ts | 6 ++---- frontend/src/queries/query.ts | 6 ++++-- frontend/src/queries/schema.json | 4 ++++ frontend/src/queries/schema.ts | 1 + frontend/src/scenes/max/maxLogic.ts | 9 ++++++--- posthog/hogql_queries/query_runner.py | 4 ++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index d6760ce8d2abe..a67918bfa0761 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -2449,8 +2449,7 @@ const api = { query: T, options?: ApiMethodOptions, queryId?: string, - refresh?: boolean, - async?: boolean, + refresh?: RefreshType, filtersOverride?: DashboardFilter | null, variablesOverride?: Record | null ): Promise< @@ -2460,13 +2459,12 @@ const api = { : T['response'] : Record > { - const refreshParam: RefreshType | undefined = refresh && async ? 'force_async' : async ? 'async' : refresh return await new ApiRequest().query().create({ ...options, data: { query, client_query_id: queryId, - refresh: refreshParam, + refresh, filters_override: filtersOverride, variables_override: variablesOverride, }, diff --git a/frontend/src/queries/query.ts b/frontend/src/queries/query.ts index 1952432e3607f..2a0af2943316e 100644 --- a/frontend/src/queries/query.ts +++ b/frontend/src/queries/query.ts @@ -15,6 +15,7 @@ import { NodeKind, PersonsNode, QueryStatus, + RefreshType, } from './schema' import { isAsyncResponse, @@ -101,12 +102,13 @@ async function executeQuery( !!featureFlagLogic.findMounted()?.values.featureFlags?.[FEATURE_FLAGS.QUERY_ASYNC] if (!pollOnly) { + const refreshParam: RefreshType | undefined = + refresh && isAsyncQuery ? 'force_async' : isAsyncQuery ? 'async' : refresh const response = await api.query( queryNode, methodOptions, queryId, - refresh, - isAsyncQuery, + refreshParam, filtersOverride, variablesOverride ) diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json index b15cea71ad019..75b26c88bc4de 100644 --- a/frontend/src/queries/schema.json +++ b/frontend/src/queries/schema.json @@ -10478,6 +10478,10 @@ "const": "async", "type": "string" }, + { + "const": "async_except_on_cache_miss", + "type": "string" + }, { "const": "blocking", "type": "string" diff --git a/frontend/src/queries/schema.ts b/frontend/src/queries/schema.ts index 562c9bf50ada8..273605a42f6d7 100644 --- a/frontend/src/queries/schema.ts +++ b/frontend/src/queries/schema.ts @@ -1182,6 +1182,7 @@ export type LifecycleFilter = { export type RefreshType = | boolean | 'async' + | 'async_except_on_cache_miss' | 'blocking' | 'force_async' | 'force_blocking' diff --git a/frontend/src/scenes/max/maxLogic.ts b/frontend/src/scenes/max/maxLogic.ts index 16bc6fa87b2e5..4d722a6fecadd 100644 --- a/frontend/src/scenes/max/maxLogic.ts +++ b/frontend/src/scenes/max/maxLogic.ts @@ -84,9 +84,12 @@ export const maxLogic = kea([ null as string[] | null, { loadSuggestions: async () => { - const response = await api.query({ - kind: NodeKind.SuggestedQuestionsQuery, - }) + const response = await api.query( + { kind: NodeKind.SuggestedQuestionsQuery }, + undefined, + undefined, + 'async_except_on_cache_miss' + ) return response.questions }, }, diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py index 40918e51b5e97..44d5abfe3c16c 100644 --- a/posthog/hogql_queries/query_runner.py +++ b/posthog/hogql_queries/query_runner.py @@ -89,12 +89,12 @@ class ExecutionMode(StrEnum): """Use cache, unless the results are missing or stale.""" RECENT_CACHE_CALCULATE_ASYNC_IF_STALE = "async" """Use cache, kick off async calculation when results are missing or stale.""" + RECENT_CACHE_CALCULATE_ASYNC_IF_STALE_AND_BLOCKING_ON_MISS = "async_except_on_cache_miss" + """Use cache, kick off async calculation when results are stale, but block on cache miss.""" EXTENDED_CACHE_CALCULATE_ASYNC_IF_STALE = "lazy_async" """Use cache for longer, kick off async calculation when results are missing or stale.""" CACHE_ONLY_NEVER_CALCULATE = "force_cache" """Do not initiate calculation.""" - RECENT_CACHE_CALCULATE_ASYNC_IF_STALE_AND_BLOCKING_ON_MISS = "async_except_on_cache_miss" - """Use cache, kick off async calculation when results are stale, but block on cache miss.""" _REFRESH_TO_EXECUTION_MODE: dict[str | bool, ExecutionMode] = {