Skip to content

Commit

Permalink
perf(max): Use async_except_on_cache_miss in question suggestions (#…
Browse files Browse the repository at this point in the history
…25803)

Co-authored-by: Georgiy Tarasov <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 28, 2024
1 parent 43b36df commit 70917b9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
6 changes: 2 additions & 4 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2449,8 +2449,7 @@ const api = {
query: T,
options?: ApiMethodOptions,
queryId?: string,
refresh?: boolean,
async?: boolean,
refresh?: RefreshType,
filtersOverride?: DashboardFilter | null,
variablesOverride?: Record<string, HogQLVariable> | null
): Promise<
Expand All @@ -2460,13 +2459,12 @@ const api = {
: T['response']
: Record<string, any>
> {
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,
},
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
NodeKind,
PersonsNode,
QueryStatus,
RefreshType,
} from './schema'
import {
isAsyncResponse,
Expand Down Expand Up @@ -101,12 +102,13 @@ async function executeQuery<N extends DataNode>(
!!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
)
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10478,6 +10478,10 @@
"const": "async",
"type": "string"
},
{
"const": "async_except_on_cache_miss",
"type": "string"
},
{
"const": "blocking",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ export type LifecycleFilter = {
export type RefreshType =
| boolean
| 'async'
| 'async_except_on_cache_miss'
| 'blocking'
| 'force_async'
| 'force_blocking'
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/scenes/max/maxLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export const maxLogic = kea<maxLogicType>([
null as string[] | null,
{
loadSuggestions: async () => {
const response = await api.query<SuggestedQuestionsQuery>({
kind: NodeKind.SuggestedQuestionsQuery,
})
const response = await api.query<SuggestedQuestionsQuery>(
{ kind: NodeKind.SuggestedQuestionsQuery },
undefined,
undefined,
'async_except_on_cache_miss'
)
return response.questions
},
},
Expand Down
4 changes: 2 additions & 2 deletions posthog/hogql_queries/query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down

0 comments on commit 70917b9

Please sign in to comment.